ASE中的命令行实用工具isql的几个参数的使用方法

在Sybase ASE中isql是个小巧而灵活的命令行实用工具。本人非常喜欢用这个工具,无论备份恢复、创建大到数据库小到表索引、配置参数、查看数据库的监控信息、 分析dbcc的命令结果等等我都喜欢用isql来实现。有些用图形界面工具能够实现的功能,我都揣摩如何用命令来实现的,因为在ASE中所有用图形界面能 够实现的功能操作都是可以用命令来完成的(当然图形工具还不能实现的地方太多)。我几乎不用sybase central,感觉这个工具既难用还低级简单。

下面介绍isql工具的使用方法。

呵呵,一些简单的命令参数我就不在这赘述了。我想每个sybase DBA对isql应该再熟悉不过了。今天我仅仅介绍几个本人自认为不太常用但是又比较实用的命令参数。

首先,查看一下isql这个工具都有哪些参数。

可能大家都知道在windows下用程序文件名称后面加空格再加上/? 来查看命令帮助。但是,对isql不能这么用。需要输入isql --help,如下图显示结果(有省略)

C:\Documents and Settings\Administrator>isql --help
usage: isql [option1] [option2] ... where [options] are ...
  -b                   Disables the display of the table headers output.
  -e                   Echoes input.
  -F                   Enables the FIPS flagger.
  -p                   Prints performance statistics.
  -n                   Removes numbering and the prompt symbol when used with -e.
  -v                   Prints the version number and copyright message.
  -W                   Turn off extended password encryption on connection retries.
  -X                   Initiates the login connection to the server with client-side
                       password encryption.
  -Y                   Tells the Adaptive Server to use chained transactions.
  -Q                   Enables the HAFAILOVER property.

 

如果输入 isql --h ,则返回简化版的命令参数。

C:\Documents and Settings\Administrator>isql --h
Syntax Error in '--h'.
usage: isql [-b] [-e] [-F] [-p] [-n] [-v] [-W] [-X] [-Y] [-Q]
        [-a display_charset] [-A packet_size] [-c cmdend] [-D database]
        [-E editor] [-h header] [-H hostname] [-i inputfile]
        [-I interfaces_file] [-J client_charset] [-K keytab_file]
        [-l login_timeout] [-m errorlevel] [-M labelname labelvalue]
        [-o outputfile] [-P password] [-R remote_server_principal]
        [-s col_separator] [-S server_name] [-t timeout] [-U username]
        [-V [security_options]] [-w column_width] [-y sybase directory]
        [-z localename] [-Z security_mechanism] [-x trusted.txt_file]
        [--retserverror] [--conceal [wildcard]] [--help]

 

今天仅介绍 -b, -e, -n,-E,-s,-w这六个参数的使用情况。

(1) 对于-b,命令参数的解释为:Disables the display of the table headers output。也就是不显示表的标题行。

如下面代码所示:

C:\Documents and Settings\Administrator>isql -Usa -Stest -b -Dandkylee
Password:
1> select * from testa
2> go
           1 aaaaaa
           2 bbbbbb
           3 ccccccc
(3 rows affected)

(2)  对于参数-e 和 -n ,-n要依附于-e来使用。

-e 表示Echoes input,也就是回显sql语句。

-n 表示Removes numbering and the prompt symbol when used with -e,也就是不显示sql语句前面的行号。

-e的用法如下:

C:\Documents and Settings\Administrator>isql -Usa -Stest -e -Dandkylee
Password:
1> select db_name()
2> go
1> select db_name()
 ------------------------------
 andkylee
(1 row affected)
1> select * from testa
2> go
1> select * from testa
 id          name
 ----------- ------------------------------
           1 aaaaaa
           2 bbbbbb
           3 ccccccc
(3 rows affected)

-e 和 -n 的联合用法如下:

C:\Documents and Settings\Administrator>isql -Usa -Stest -e  -n -Dandkylee
Password:
select db_name()
go
select db_name()
 ------------------------------
 andkylee
(1 row affected)
select * from testa
go
select * from testa
 id          name
 ----------- ------------------------------
           1 aaaaaa
           2 bbbbbb
           3 ccccccc
(3 rows affected)

这时候你可能在怀疑了,上面我都输入了sql语句,我还要在返回结果中回显刚才输入的sql语句干什么?

的确,这个地方不是-e的应用场景。如果你用isql执行一个sql文件,并想把返回的结果保存到一个文件中,那么这个时候-e就有用处了。isql会在每个sql语句的执行结果前面加上相应的sql语句,这样看起来就很方便了。

简单举个例子:

假设有d:\test_isql.txt,里面的内容为:

select db_name()
go
select * from testa
go

我执行如下的命令参数:isql -Usa  -P -Stest -Dandkylee -e   -id:\test_isql.txt -od:\test_isql_result.txt

查看d:\test_isql_result.txt的文件内容为:

1> select db_name()
                               
 ------------------------------
 andkylee                      
(1 row affected)
1> select * from testa
 id          name                          
 ----------- ------------------------------
           1 aaaaaa                        
           2 bbbbbb                        
           3 ccccccc                       
(3 rows affected)
 

对每个语句的执行结果一目了然,非常直观。

(3) -E 参数的使用

-E editor的意思是:Specifies an editor other than the default editor vi,也就是你可以指定一个文本编辑器用来在isql会话过程中编辑sql语句。这一点和sqlplusw中的ed命令是一模一样的。

多说一点,通过other than the default editor vi字面意思就可以看出,windows下的isql和unix下的isql有点不同。unix的isql下默认就可以使用vi进行编辑sql语句,但是 windows上的isql必须手动指定文本编辑器才能够使用这个功能。

C:\Documents and Settings\Administrator>isql -Usa -Stest -Enotepad -Dandkylee
Password:
1> notepad
[sh:notepad D:\PROGRA~1\ADMINI~1\LOCALS~1\Temp\cti9CE.tmp]
1> select db_name()
2> go
3> reset
1> notepad
[sh:notepad D:\PROGRA~1\ADMINI~1\LOCALS~1\Temp\cti9CE.tmp]
1> select db_name()
2> go
 ------------------------------
 andkylee
(1 row affected)

使用方法是在isql的连接参数中加上-Enotepad(或者其它的文本编辑器,如notepad2,editlus都行,只要在win+R中能够成功执行的都可以!)

然后在提示符下输入notepad加上回车,就会弹出一个记事本让你进行编辑sql语句。这样是不是很方便,尤其在执行很长的sql语句的时候。哪 怕输错一点点都要reset再重新输入一遍。 这样就可以在文本编辑器中编辑好了再去执行了。(呵呵,可能你会说? 不能在记事本中编辑好了直接复制粘贴到isql下执行吗?当然可以! )

另外需着重注意一点,在文本编辑器中编辑的sql语句不能带有go,大家可以在我上面的演示代码中看出这一点。这个苛刻的要求就限制了我们不能在文本编辑器中输入多个sql语句命令。只能一个一个得来。


(4)  再来介绍今天的最后两个参数 -s -w, 我也是最近才开始使用这个参数-s的。感觉挺好。

-s col_separator的意思是:Resets the column separator character, which is blank by default,也就是说,你可以重新指定新的列分割符来替代默认的空格分隔符。

-w column_width 的意思是:Sets the screen width for output,也就是说,你可以指定屏幕的显示宽度(是像素还是字节,我没搞清楚)。

我把这两个参数放在一起使用,感觉效果很不错。请看下面的显示结果:

C:\Documents and Settings\Administrator>isql -Usa -Stest -Enotepad -s"|" -w5000
Password:
1> use andkylee
2> go
1> select *  from test
2> go
|id         |name                          |net_type|colc      |COLD|COLE|
|-----------|------------------------------|--------|----------|----|----|
|          1|liu                           |NULL    |1         |NULL|NULL|
|          1|liu                           |NULL    |1         |NULL|NULL|
|          2|zhang                         |NULL    |1         |NULL|NULL|
|          3|邓啟中                        |1       |1         |NULL|0   |
(4 rows affected)
1>

 

在这里我把列分割符替换成了|,显示出来的效果如上。 是不是有点类似mysql的显示效果?我把屏幕的宽度设置成了-w5000。同时需要注意的是:你也需要把cmd的屏幕宽度设置大些。在命令提示符cmd 的属性里选择布局,调整屏幕缓冲区里面的宽度。这样就会显示类似上面的效果了。

执行一个字段多点的表,看看效果吧!

1> select  * from sysobjects
2> where id< 20
3> go
|name                                                                                                                                                                                                                                                           |id         |uid        |type|userstat|sysstat|indexdel|schemacnt|sysstat2   |crdate                    |expdate                   |deltrig    |instrig    |updtrig    |seltrig    |ckfirst    |cache |audflags   |objspare   |versionts                 |loginame                      |identburnmax                             |spacestate|erlchgts          |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|-----------|----|--------|-------|--------|---------|-----------|--------------------------|--------------------------|-----------|-----------|-----------|-----------|-----------|------|-----------|-----------|--------------------------|------------------------------|-----------------------------------------|----------|------------------|
|sysobjects                                                                                                                                                                                                                                                     |          1|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysindexes                                                                                                                                                                                                                                                     |          2|          1|S   |       0|     97|       0|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|syscolumns                                                                                                                                                                                                                                                     |          3|          1|S   |       0|     97|       0|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|systypes                                                                                                                                                                                                                                                       |          4|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysprocedures                                                                                                                                                                                                                                                  |          5|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|syscomments                                                                                                                                                                                                                                                    |          6|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|syssegments                                                                                                                                                                                                                                                    |          7|          1|S   |       0|     65|       0|        0|      98304|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|syslogs                                                                                                                                                                                                                                                        |          8|          1|S   |       0|      1|       0|        0|      73728|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|      NULL|NULL              |
|sysprotects                                                                                                                                                                                                                                                    |          9|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysusers                                                                                                                                                                                                                                                       |         10|          1|S   |       0|     97|       3|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysalternates                                                                                                                                                                                                                                                  |         11|          1|S   |       0|     97|       1|        0|     229888|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysdepends                                                                                                                                                                                                                                                     |         12|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|syskeys                                                                                                                                                                                                                                                        |         13|          1|S   |       0|     97|       1|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysgams                                                                                                                                                                                                                                                        |         14|          1|S   |       0|      1|       0|        0|      73728|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|      NULL|NULL              |
|sysusermessages                                                                                                                                                                                                                                                |         15|          1|S   |       0|    113|       2|        0|      73728|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|      NULL|NULL              |
|sysreferences                                                                                                                                                                                                                                                  |         16|          1|S   |       0|     97|       3|        0|     229376|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysconstraints                                                                                                                                                                                                                                                 |         17|          1|S   |       0|     97|       2|        0|     229888|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|systhresholds                                                                                                                                                                                                                                                  |         18|          1|S   |       0|     65|       0|        0|      98304|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
|sysroles                                                                                                                                                                                                                                                       |         19|          1|S   |       0|     97|       1|        0|     229888|       Dec  2 2009  6:58PM|       Dec  2 2009  6:58PM|          0|          0|          0|          0|          0|     0|          0|          0|NULL                      |NULL                          |                                     NULL|         1|0x0000000000000000|
(19 rows affected)
1>
 

(你要是发现比|还好的列分割符号,麻烦告诉我一下。谢谢!)

(5) 最后,介绍一个对于显示结果非常实用的存储过程sp_autoformat.

我也是在浏览一些系统存错过程源代码的时候发现的这个过程。这个是sybase 未公开的系统过程,用来格式化输出结果。如果想看这个过程的语法,请到sybsystemprocs里面查找。

看个效果吧!

1> sp_autoformat sysobjects,@whereclause="where id < 20"
2> go
|name           |id|uid|type|userstat|sysstat|indexdel|schemacnt|sysstat2|crdate             |expdate            |deltrig|instrig|updtrig|seltrig|ckfirst|cache|audflags|objspare|versionts                 |loginame|identburnmax|spacestate|erlchgts          |
|---------------|--|---|----|--------|-------|--------|---------|--------|-------------------|-------------------|-------|-------|-------|-------|-------|-----|--------|--------|--------------------------|--------|------------|----------|------------------|
|sysobjects     | 1|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysindexes     | 2|  1|S   |       0|     97|       0|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|syscolumns     | 3|  1|S   |       0|     97|       0|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|systypes       | 4|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysprocedures  | 5|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|syscomments    | 6|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|syssegments    | 7|  1|S   |       0|     65|       0|        0|   98304|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|syslogs        | 8|  1|S   |       0|      1|       0|        0|   73728|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|      NULL|NULL              |
|sysprotects    | 9|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysusers       |10|  1|S   |       0|     97|       3|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysalternates  |11|  1|S   |       0|     97|       1|        0|  229888|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysdepends     |12|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|syskeys        |13|  1|S   |       0|     97|       1|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysgams        |14|  1|S   |       0|      1|       0|        0|   73728|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|      NULL|NULL              |
|sysusermessages|15|  1|S   |       0|    113|       2|        0|   73728|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|      NULL|NULL              |
|sysreferences  |16|  1|S   |       0|     97|       3|        0|  229376|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysconstraints |17|  1|S   |       0|     97|       2|        0|  229888|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|systhresholds  |18|  1|S   |       0|     65|       0|        0|   98304|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
|sysroles       |19|  1|S   |       0|     97|       1|        0|  229888|Dec  2 2009  6:58PM|Dec  2 2009  6:58PM|      0|      0|      0|      0|      0|    0|       0|       0|NULL                      |NULL    |        NULL|         1|0x0000000000000000|
(19 rows affected)
(return status = 0)

 

(6) 补充,参数-p,显示性能统计信息.

参数-p:Prints performance statistics,与之对应的是会话级别的set statistics time on 。这两个方法都能够显示出 统计信息,但是,会话级别的set statistics time on比参数-p的显示结果更详细些。

示例如下:

利用参数-p来显示简要统计信息:

C:\Documents and Settings\Administrator>isql -Usa -P -p
1> select count(*) from sysobjects
2> go
 -----------
         160
(1 row affected)
Execution Time (ms.):      0            Clock Time (ms.):      0

在每个SQL语句的最后显示执行时间和耗用时间。

会话级别的选项set statistics time on 显示比较详细的统计时间:

C:\Documents and Settings\Administrator>isql -Usa -P
1>
2> set statistics time on
3> go
Execution Time 0.
Adaptive Server cpu time: 0 ms.  Adaptive Server elapsed time: 0 ms.
1> select count(*) from sysobjects
2> go
Parse and Compile Time 0.
Adaptive Server cpu time: 0 ms.
 -----------
         160
Execution Time 0.
Adaptive Server cpu time: 0 ms.  Adaptive Server elapsed time: 0 ms.
(1 row affected)
1>

由上可以看出,会话级别选项set statistics time on会显示解析和编译时间、SQL执行时间、以及总计的执行时间、耗用时间。

啰啰嗦嗦就介绍这么多吧!

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:isql -b -e -E -n -s -w 命令实用工具 sp_autoformat
————————————————————————————————-

  • 本文链接地址:http://www.sybrepair.com/sybase-ase-cmdline-utility-isql-new-features.htm
  • 本文为dbainfo个人原创,请在尊重作者劳动成果的前提下进行转载;
  • 转载务必注明原始出处 : Sybase数据库技术,数据库恢复专家
  • 对《ASE中的命令行实用工具isql的几个参数的使用方法》有何疑问或见解,请在本文下方发表;
  • 对网站还有其他问题或建议,请提交在留言板,谢谢!
  • 目前还没有任何评论.
    :wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)