存档

2010年 的存档,文章数:148

一、添加镜像

为master设备添加镜像设备:

1> disk mirror
2> name='master',
3> mirror='D:\sybase\data\master_mirr.dat'
4> go
Msg 5155, Level 16, State 1:
Server 'TEST', Line 1:
The command 'DISK MIRROR' cannot be executed since disk mirroring has been
disabled. In order to enable disk mirroring, use: sp_configure 'disable disk
mirroring',0 and restart the server.

 

ASE默认是关闭设备镜像功能的,需要配置参数启用。disable disk mirroring 这是一个静态参数,配置完之后需要重启ASE服务器。

1> sp_configure "disable disk mirroring",0
2> go
 Parameter Name                 Default     Memory Used Config Value
         Run Value    Unit                 Type
 ------------------------------ ----------- ----------- ------------
         ------------ -------------------- ----------
 disable disk mirroring                   1           0            0
                    1 switch               static
(1 row affected)
Configuration option changed. Since the option is static, Adaptive Server must
be rebooted in order for the change to take effect.
Changing the value of 'disable disk mirroring' to '0' reduces the amount of
memory ASE uses by 18636 K. The reduced memory may be reused when this configure
value changes, but will not be released until ASE restarts.
(return status = 0)

 

重启ASE服务器之后。

执行命令镜像master设备

1> disk mirror
2> name='master',
3> mirror='D:\sybase\data\master_mirr.dat'
4> go
Creating the physical file for the mirror...
Starting Dynamic Mirroring of 20480 pages for logical device 'master'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
The remaining 10752 pages are currently unallocated and will be mirrored as they
are allocated.
1>

 

成功完成!

利用过程sp_helpdevice查看master设备目前的状态。

1> sp_helpdevice master
2> go
 device_name physical_name
         description
         status cntrltype vdevno vpn_low vpn_high
 ----------- -------------------------
         -------------------------------------------------------------------------
         ------ --------- ------ ------- --------
 master      D:\sybase\data\master.dat
         file system device, special, MIRROR ENABLED, mirror = 'D:\sybase\data\m
         aster_mirr.dat',
serial writes, dsync on, directio off, reads mirrored,
          default disk, physical disk, 80.00 MB, Free: 42.00 MB
            739         0      0       0    40959
(1 row affected)
 dbname      size          allocated           vstart lstart
 ----------- ------------- ------------------- ------ ------
 master           26.00 MB Dec  2 2009  6:58PM      4      0
 model             6.00 MB Dec  2 2009  6:58PM  13316      0
 sybsystemdb       6.00 MB Dec  2 2009  6:58PM  19460      0
(1 row affected)
(return status = 0)

 

下面来解析一下被镜像后master设备的状态字段。

master设备被镜像后,在sysdevices系统表中并没有增加记录行;仅仅是更新了master设备对应的记录行中的status和mirrorname两个字段的内容。

1> select * from sysdevices
2> where name='master'
3> go
 low         high        status cntrltype name                           phyname                                                                                                                         mirrorname                                                                                                                      vdevno      crdate                     resizedate                 status2
 ----------- ----------- ------ --------- ------------------------------ ------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------- ----------- -------------------------- -------------------------- -----------
           0       40959    739         0 master                         D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat                                                                                                            0        Dec  2 2009  6:58PM        Mar 27 2010  4:32PM           0
(1 row affected)
1>
 

从上面可以看出master设备对应的status变成了739。status字段用bit位来表示各个状态的信息。

739 = 1 + 2 + 32 + 64 + 128 + 512

其中:

1:缺省磁盘; 

2:物理磁盘 

32:串行写 

64:设备已镜像 

128: 读已镜像

512:已允许镜像

这几个状态和sp_helpdevice master 中查看到的相一致。 呵呵, 要是看过sp_helpdevice的源代码的话,自然很好理解。

 

二、取消镜像

unmirror分两种情况:user-initiated 和 system-initiated 。 在镜像设备上如果出现了IO错误会导致系统自动取消该设备的镜像。

用户手动取消镜像的语法为:

 disk unmirror

name="logical_device_name"

[,side={"primary"|secondary}]

[,mode={retain|remove}]

其中side和mode两个选项是可选的。side的默认值为:secondary,意思是取消哪一边的镜像设备(有主设备和镜像设备两个)。 mode的默认值是retain,意思是本次取消是临时的(retain,下次还可以激活设备以再次用来镜像)还是永久的(remove,删除设备了)。

下面测试临时取消master设备的镜像功能!

1> disk unmirror
2> name='master',side=secondary,mode=retain
3> go
1>

 

执行完,没有任何提示信息。在errlog文件中看到有这么一条信息:00:00000:00030:2010/06/07 13:20:59.59 kernel  Closing the secondary device for virtual device master

现在再来看看master设备的状态信息:

1> sp_helpdevice master
2> go
 device_name physical_name             description                                                                                                                                                                                           status cntrltype vdevno vpn_low vpn_high
 ----------- ------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------ --------- ------ ------- --------
 master      D:\sybase\data\master.dat file system device, special, MIRROR DISABLED, mirror = 'D:\sybase\data\master_mirr.dat', serial writes, dsync on, directio off, reads mirrored, default disk, physical disk, 80.00 MB, Free: 42.00 MB   2275         0      0       0    40959
(1 row affected)
 dbname      size          allocated           vstart lstart
 ----------- ------------- ------------------- ------ ------
 master           26.00 MB Dec  2 2009  6:58PM      4      0
 model             6.00 MB Dec  2 2009  6:58PM  13316      0
 sybsystemdb       6.00 MB Dec  2 2009  6:58PM  19460      0
(1 row affected)
(return status = 0)
1> select * from sysdevices where name='master'
2> go
 low         high        status cntrltype name                           phyname                                                                                                                         mirrorname                                                                                                                      vdevno      crdate                     resizedate                 status2
 ----------- ----------- ------ --------- ------------------------------ ------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------- ----------- -------------------------- -------------------------- -----------
           0       40959   2275         0 master                         D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat                                                                                                            0        Dec  2 2009  6:58PM        Mar 27 2010  4:32PM           0
(1 row affected)
1>
 

sp_helpdevice显示master设备已被MIRROR DISABLED。 sysdevices系统表中master对应的status列为:2275 = 2048 + 128 + 64 + 32 + 2 + 1 。状态为2048表示镜像已禁用(内部使用)。


三、重新激活镜像

语法:disk remirror name="logical_device_name"

在设备的镜像功能因为用户或者系统的缘故而被中止时,可以利用此命令恢复设备上的镜像功能。发出该命令后,ASE服务器会将镜像主设备上的数据拷贝到镜像次设备上面去。

恢复本文上面暂时取消的master上的镜像。

1> disk remirror
2> name='master'
3> go
Starting Dynamic Mirroring of 20480 pages for logical device 'master'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
The remaining 10752 pages are currently unallocated and will be mirrored as they are allocated.
1>
 

在errorlog文件中有下面的日志内容:00:00000:00030:2010/06/07 13:31:03.26 kernel  mirror for virtual device 0 started using asynchronous (with DIRECTIO) I/O

再次查看status状态信息,

1> select name,status,phyname,mirrorname from sysdevices where name='master'
2> go
 name                           status phyname                                                                                                                         mirrorname
 ------------------------------ ------ ------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------
 master                            739 D:\sybase\data\master.dat                                                                                                       D:\sybase\data\master_mirr.dat
(1 row affected)

 

可以看到重新恢复镜像后,master设备的status状态信息和刚开始添加镜像时相同。个人感觉重新激活镜像(remirror)和新添加镜像 已经是一样的。只是不用告诉系统镜像到什么位置了而已;还有初次镜像的时候secondary设备文件必须不存在而激活镜像则相反。

 

四、利用镜像功能来移动设备的物理位置

可以利用镜像功能将数据库设备移动到其它物理位置。比如设备A原来在C盘,要是将其移动到D盘。 需要两个步骤:

1.将设备A镜像到D盘的设备文件上;

2.取消设备A在C盘的主镜像文件。

下面演示将tempdb的设备文件由D:\sybase\data\tempdbdev.dat移动到D:\syb_data\tempdbdev.dat

1> disk mirror
2> name='tempdbdev',
3> mirror='d:\syb_data\tempdbdev.dat'
4> go
Creating the physical file for the mirror...
Starting Dynamic Mirroring of 51200 pages for logical device 'tempdbdev'.
         512 pages mirrored...
        1024 pages mirrored...
        1536 pages mirrored...
        2048 pages mirrored...
        2560 pages mirrored...
        3072 pages mirrored...
        3584 pages mirrored...
        4096 pages mirrored...
        4608 pages mirrored...
        5120 pages mirrored...
        5632 pages mirrored...
        6144 pages mirrored...
        6656 pages mirrored...
        7168 pages mirrored...
        7680 pages mirrored...
        8192 pages mirrored...
        8704 pages mirrored...
        9216 pages mirrored...
        9728 pages mirrored...
       10240 pages mirrored...
       10752 pages mirrored...
       11264 pages mirrored...
       11776 pages mirrored...
       12288 pages mirrored...
       12800 pages mirrored...
       13312 pages mirrored...
       13824 pages mirrored...
       14336 pages mirrored...
       14848 pages mirrored...
       15360 pages mirrored...
       15872 pages mirrored...
       16384 pages mirrored...
       16896 pages mirrored...
       17408 pages mirrored...
       17920 pages mirrored...
       18432 pages mirrored...
       18944 pages mirrored...
       19456 pages mirrored...
       19968 pages mirrored...
       20480 pages mirrored...
       20992 pages mirrored...
       21504 pages mirrored...
       22016 pages mirrored...
       22528 pages mirrored...
       23040 pages mirrored...
       23552 pages mirrored...
       24064 pages mirrored...
       24576 pages mirrored...
       25088 pages mirrored...
       25600 pages mirrored...
       26112 pages mirrored...
       26624 pages mirrored...
       27136 pages mirrored...
       27648 pages mirrored...
       28160 pages mirrored...
       28672 pages mirrored...
       29184 pages mirrored...
       29696 pages mirrored...
       30208 pages mirrored...
       30720 pages mirrored...
       31232 pages mirrored...
       31744 pages mirrored...
       32256 pages mirrored...
       32768 pages mirrored...
       33280 pages mirrored...
       33792 pages mirrored...
       34304 pages mirrored...
       34816 pages mirrored...
       35328 pages mirrored...
       35840 pages mirrored...
       36352 pages mirrored...
       36864 pages mirrored...
       37376 pages mirrored...
       37888 pages mirrored...
       38400 pages mirrored...
       38912 pages mirrored...
       39424 pages mirrored...
       39936 pages mirrored...
       40448 pages mirrored...
       40960 pages mirrored...
       41472 pages mirrored...
       41984 pages mirrored...
       42496 pages mirrored...
       43008 pages mirrored...
       43520 pages mirrored...
       44032 pages mirrored...
       44544 pages mirrored...
       45056 pages mirrored...
       45568 pages mirrored...
       46080 pages mirrored...
       46592 pages mirrored...
       47104 pages mirrored...
       47616 pages mirrored...
       48128 pages mirrored...
       48640 pages mirrored...
       49152 pages mirrored...
       49664 pages mirrored...
       50176 pages mirrored...
       50688 pages mirrored...
       51200 pages mirrored...
1> disk unmirror
2> name='tempdbdev',
3> side='primary',
4> mode=remove
5> go
1> sp_helpdevice tempdbdev
2> go
 device_name physical_name             description                                                                                  status cntrltype vdevno vpn_low vpn_high
 ----------- ------------------------- -------------------------------------------------------------------------------------------- ------ --------- ------ ------- --------
 tempdbdev   d:\syb_data\tempdbdev.dat file system device, special, dsync on, directio off, physical disk, 200.00 MB, Free: 0.00 MB  16386         0      2       0   102399
(1 row affected)
 dbname size          allocated           vstart lstart
 ------ ------------- ------------------- ------ ------
 tempdb     100.00 MB Dec  2 2009  7:01PM      0      0
 tempdb      50.00 MB Dec  8 2009 11:16AM  51200  25600
 tempdb      50.00 MB Dec  8 2009 11:16AM  76800  38400
(1 row affected)
(return status = 0)
1> select name,status,phyname,mirrorname from sysdevices where name='tempdbdev'
2> go
 name                           status phyname                                                                                                                         mirrorname
 ------------------------------ ------ ------------------------------------------------------------------------------------------------------------------------------- -------------
 tempdbdev                       16386 d:\syb_data\tempdbdev.dat                                                                                                       NULL
(1 row affected)
1>
 

对应于errorlog中的信息为: 00:00000:00030:2010/06/07 13:45:33.34 kernel  mirror for virtual device 2 started using asynchronous I/O
00:00000:00030:2010/06/07 13:46:56.00 kernel  Closing the primary device for virtual device tempdbdev
00:00000:00030:2010/06/07 13:46:56.00 kernel  The new primary device is now d:\syb_data\tempdbdev.dat

其中status:16386 = 16384 + 2 这是一个普通的物理设备文件。

 

五、对master设备进行镜像的另外一种方法

对master设备镜像还有一种方法,就是直接利用命令参数。 windows下sqlsrvr.exe的参数中有个是: -r mirror_file          - master device's mirror device name

可以修改RUN_SEVERNAME文件来加入-r这个参数来镜像master设备。

如改为:

D:\sybase\ASE-15_0\bin\sqlsrvr.exe  -dD:\sybase\data\master.dat -sTEST -eD:\sybase\ASE-15_0\install\TEST.log -iD:\sybase\ini -MD:\sybase\ASE-15_0 -rd:\syb_data\master_mirr.dat

 

在windows下的ASE还需要修改注册表中的配置信息, 才能用系统工具中的服务正常启动数据。 不过你要是习惯每次都用RUN_SERVERNAME这个命令行来启动数据库的话, 也不用改注册表了。至于如何改注册表, 本篇暂时不介绍。

好了,关于ASE中的mirror就介绍这么多吧。

 

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:mirror unmirror remirror 镜像  移动设备
————————————————————————————————-

本人的pc机上装的数据库比较多。有:oracle 10g,MySQL5.0.45,Sybase ASE15.0.3,Sybase IQ15.1,MSSQLSERVER2005,MSSQLSERVER2000,Sybase Anywhere8,Sybase Anywhere9,Sybase Anywhere10等等。还有非安装版的Sybase ASE12.5.x,ASA5,ASA6等。

数据库比较多,都通过系统工具中的服务项来启动不太现实。有时用到的时候直接用命令行启动,这样挺方便。注册表信息也省得维护了。

最近,在用SQLSERVER2005 management studio读取表数据的时候,报了下面的两个错误。

在对象资源管理器中找到sqlserver2000数据库中的用户表,点右键“打开表”报错如下:

标题: Microsoft SQL Server Management Studio
------------------------------
调用的目标发生了异常。 (SQLEditors)
------------------------------
其他信息:
找不到请求的 .Net Framework 数据提供程序。可能没有安装。 (System.Data)
 

在对象资源管理器中找到sqlserver2005中某个用户数据库中的用户表,点右键“打开表”报错如下:

标题: Microsoft SQL Server Management Studio
------------------------------
调用的目标发生了异常。 (SQLEditors)
------------------------------
其他信息:
创建 system.data 的配置节处理程序时出错: 列“InvariantName”被约束为是唯一的。值“iAnywhere.Data.SQLAnywhere”已存在。 (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line 126) (System.Configuration)
------------------------------
列“InvariantName”被约束为是唯一的。值“iAnywhere.Data.SQLAnywhere”已存在。 (System.Data)
 

问题怎么解决呢?

在网上搜索了很多,有说和MySQL有关的。的确我的pc上有MySQL5.0.45。但是将MySQL的相关项目去掉还是不管用。这些链接如下,

大家可以参考下:

找不到请求的 .Net Framework 数据提供程序。可能没有安装。

MySql “找不到请求的 .Net Framework 数据提供程序。可能没有安装。”解决方法

ASP.NET 2.0中如何连接到Mysql

根据访问sqlserver2005数据库时的报错,可能和.NET FRAMEWORK的配置文件有关系。查看C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG 下的machine.config文件。发现的DbProviderFactories节下的最后四个项目为:

  <add name="SQL Anywhere 10 Data Provider" invariant="iAnywhere.Data.SQLAnywhere" description=".Net Framework Data Provider for SQL Anywhere 10" type="iAnywhere.Data.SQLAnywhere.SAFactory, iAnywhere.Data.SQLAnywhere,  Version=10.0.1.34152, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />
     
     <add name="SQL Anywhere UltraLite.NET 10 Data Provider" invariant="iAnywhere.Data.UltraLite" description=".Net Framework Data Provider for SQL Anywhere UltraLite.NET 10" type="iAnywhere.Data.UltraLite.ULFactory, iAnywhere.Data.UltraLite,  Version=10.0.1.3415, Culture=neutral, PublicKeyToken=ff11483eb5a8c1a5" />
     
     <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.0.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> 
     
     <add name="SQL Anywhere 11 Data Provider" invariant="iAnywhere.Data.SQLAnywhere" description=".Net Framework Data Provider for SQL Anywhere 11" type="iAnywhere.Data.SQLAnywhere.SAFactory, iAnywhere.Data.SQLAnywhere, Version=2, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />

根据列"InvariantName"被约束为是唯一的。值"iAnywhere.Data.SQLAnywhere"已存在。观察到SQL Anywhere 10 Data Provider 和 SQL Anywhere 11 Data Provider 这两个项目下的 invariant 都是 "iAnywhere.Data.SQLAnywhere",尝试着将"SQL Anywhere 11 Data Provider"项目删除 ,然后重新打开management studio,问题解决。

总结一下:问题不在于微软的.NET FRAMEWORK3.5的安装时间先后的问题, 是Sybase公司的Anywhere起的驱动程序名称的问题。iAnywhere.Data.UltraLite 就没问题。 为什么SQL Anywhere 10和SQL Anywhere 11 都对应一样相同的Invariant名称呢?

如果ASA10和ASA11都装在一台机器上,就肯定会出现这个问题。 不敢把SQL Anywhere 11 Data Provider对象的 invariant改为:iAnywhere.Data.SQLAnywhere11。反正我也不做数据库开发,我只关系数据库管理方面的。 二者取其一,将SQL Anywhere 11 Data Provider项目暂时注释掉,

 <!-- <add name="SQL Anywhere 11 Data Provider" invariant="iAnywhere.Data.SQLAnywhere" description=".Net Framework Data Provider for SQL Anywhere 11" type="iAnywhere.Data.SQLAnywhere.SAFactory, iAnywhere.Data.SQLAnywhere, Version=2, Culture=neutral, PublicKeyToken=f222fc4333e0d400" />  -->

保存machine.config,重新启动management studio。 问题解决。 o(≧v≦)o~~

 

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:ASA 10 11 SQLSERVER management studio  DbProvider InvariantName
————————————————————————————————-

本文给出sybase IQ15.1试用版在试用一个月到期之后继续试用的两种方法。

第一种:删除注册表后重新安装

Sybase IQ作为数据分析以及数据仓库的一款数据库管理系统,目前最新版本为15.5。我手头上使用的这份为公司从sybase公司那里领用的试用版,有效期只有一个月。

Sybase IQ15.1 for windows的安装介质CD光盘包含32bit和64bit两类平台的安装程序。我在自己的windows-xp(32bit)上安装了sybase IQ15.1。在安装过程中要求选择产品类型的时候,我从两个备选项:开发版和体验版中选择了开发版,一个月之后sybase IQ就启动不起来了,报没有可用license的问题。

在我的pc上ASE15.0.3和IQ15.1是共用d:\sybase这个%SYBASE%目录的,所以默认的认证文件夹也在D:\sybase \SYSAM-2_0,该文件夹内只有一个文件:SYBASE_ASE_DE.lic;且这个文件的修改日期也是很早之前了。心里有点疑惑。

不管三七二十一先重装一遍IQ再说,结果装完之后,原来的iq库还是因为没有可用license而启动不起来。心里很窝火哦。

又想到一个办法,把sybase IQ的注册表项目都删除,然后又重装了一遍,这次IQ可以启动起来了。 

步骤如下:

第一步:删除sybase IQ的相关服务项目

在控制面板>管理工具>服务里面,我发现对于sybase IQ数据库仅有一个相关的服务: Sybase IQ Agent 15.1。在这一服务名Sybase IQ Agent 15.1上点右键,查看其属性,得知其服务名称为:SybaseIQAgent15。 实际上,SybaseIQAgent15此名即为该项服务的ServiceKeyName。

要想删除windows系统中的系统服务, 除了用其它的管理工具外, 系统自带了一个命令行工具sc。语法为:

C:\Documents and Settings\Administrator>sc delete
DESCRIPTION:
        Deletes a service entry from the registry.
        If the service is running, or another process has an
        open handle to the service, the service is simply marked
        for deletion.
USAGE:
        sc <server> delete [service name]

 

直接执行: sc delete SybaseIQAgent15 就可以删除此iq代理服务了。

第二步:删除的注册表项目

在开始>运行里面输入regedit打开注册表编辑器。 

定位到:HKEY_CURRENT_USER\Software\SYBASE 下面将IQ相关的子项删除,其它的不要删错了。

然后将下面的四项都删除。

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Sybase_IQ_15

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SybaseIQAgent15

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Sybase_IQ_15

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SybaseIQAgent15

之后,个人感觉为了使得上述删除生效,最好重启一下系统。我是在没重启的情况下也再次成功安装了iq15.1。

最好就是按照sybase IQ15.1了,安装过程比ASE简单多了。 因为IQ的安装过程中不牵涉到配置服务器,仅仅复制了安装程序而已。

最后启动IQ的时候,竟然成功了。 呵呵!

ps:我的pc上是先安装了ASE15.0.3,sybase的根目录是d:\sybase 。sybase的license文件是放在D:\sybase\SYSAM-2_0\licenses里面的。但是,我发现安装完iq后这个文件的修改日 期没有变,也就是说iq安装程序可能没有修改这个文件。心里一直疑惑:sybase IQ是怎么判断试用一个月到期的?

 

第二种: 调整系统时间

查看Sybase IQ15.1数据库的日志文件*.iqmsg,发现有下面的提示信息:

I. 04/30 15:07:33. 0000000000 License feature name:  IQ_SECURITY
I. 04/30 15:07:33. 0000000000 License search path:   D:\sybase\SYSAM-2_0\licenses\SYBASE_ASE_DE-Original.lic;
I. 04/30 15:07:33. 0000000000    D:\sybase\SYSAM-2_0\licenses\SYBASE_ASE_DE.lic;D:\sybase\SYSAM-2_0 -
I. 04/30 15:07:33. 0000000000    \licenses\SySAMLicenseServer.lic;D:\sybiq\*.lic
I. 04/30 15:07:33. 0000000000 FLEXnet Licensing error:-5,357
I. 04/30 15:07:33. 0000000000 For further information, refer to the Sybase Software Asset Management website at http://www.sybase.com/sysam
I. 04/30 15:07:33. 0000000000 WARNING: Sybase IQ functionality that requires the IQ_SECURITY license will be disabled on Sat May 01 00:00:00 2010, unless a suitable IQ_SECURITY license is obtained before that date.

 

是windows-xp的系统时间调整为早于:2010-05-01。最后再次启动数据库的时候,竟然启动成功了。不知道此种方法是否通用?

另外,在Sybase官网上只能下载到最新版的IQ,之前版本的介质官网不提供下载链接。想试用Sybase IQ,请联系Sybase公司,他们的销售会很热心的帮助解决的。毕竟这是帮着他们拓展市场嘛!Sybase北京公司的联系电话:(010)59215888

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:IQ 15.1 license outdate 试用 过期
————————————————————————————————-

在论坛中看到有人寻找从sybase数据 库中提取表结构的方法。用 dbartisan8.6.1这个第三方工具可以很轻松的实现,我自己也用pb编写过函数能够提取表结构和索引创建语法。
像sybase自带的sybase central也能从中导出ddl。我感觉从sybase central中导出语法时可能利用的就是ddlgen这个工具,原因我认为sybase central和ddlgen都基于java 编写。
先将整理的ddlgen说明以及使用方法贴在下面。

ddlgen

Description

A Java-based tool that generates definitions for server- and database-level objects in Adaptive Server. ddlgen supports Adaptive Server version 11.9.2 and later.

The command-line version of ddlgen is located in $SYBASE/ASEP/bin ( %SYBASE%\ASEP\bin in Windows ).

Syntax

ddlgen

-Ulogin

-Ppassword

-S[server | host_name : port_number ]

[-I interfaces_file ]

[-Tobject_type ]

[-Nobject_name ]

[-Ddbname ]

[-Xextended_object_type ]

[-Ooutput_file ]

[-Eerror_file ]

[-Lprogress_log_file ]

[-Jclient_charset ]

-F[ % | SGM | GRP | USR | R | D | UDD | U | V |
P | XP | I | RI | KC | TR | PC ]

Parameters

-U login

specifies a login name, and is case-sensitive.

-P password

specifies your password.

-S [server | host _ name : port _ number ]

specifies the name of the Adaptive Server. ddlgen looks this name up in the interfaces file or LDAP configuration file. If you specify:

·
-S [host _ name :port _ number ] –
ddlgen uses the host _ name and port _ number provided, and neither interfaces nor LDAP configuration files are read or parsed.

·
-S[server ] -I ddlgen parses the interfaces file specified at the user location for the server name (see the -I parameter description for more information).

·
-S[server ] – without specifying an interfaces file, ddlgen does the following:

a.
ddlgen first tries to read the LDAP configuration file from the standard location

b.
If the LDAP file does not exist, or exists but does not contain an Adaptive Server entry, then the interfaces file is parsed at its standard location for the server name

c.
If the LDAP file exists, then ddlgen uses it to search the server name. The interfaces file is not parsed, and the LDAP configuration file is parsed.

You must use the -S option because ddlgen does not connect to a default server.

-I

specifies the interfaces file name, and corresponds to $SYBASE/interfaces for UNIX , and %SYBASE%\ini\sql.ini for Windows. Use this optional parameter with -S .

-Tobject _ type

specifies the type of object you are creating. If you do not use -T , ddlgen generates DDL for the default database of login. The object types for -T are:

 

Object type  Description 
C  cache
D  default
DB  database
DBD  database device
DPD  dump device
EC  execution class
EG  engine group
EK  encrypted keys
GRP  group
I  index
KC  key constraints
L  login
LK  logical key
P  stored procedure
R  rule
RI  referential integrity
RO  role
RS  remote server
SGM  segment
TR  trigger
U  table
UDD  user-defined datatype
USR  user
V  view
WS  user-defined Web service
WSC  Web service consumer
XP  extended stored procedure

 

-Nobject _ name

specifies the fully qualified name of the object you are creating, such as -Ndb _ name .owner _ name .table _ name .object _ name . The -N option:

·
is required if you specify any object _ type other than DB (database) in the -T parameter.

·
accepts wildcards with the use of % .

·
generates DDL for all items of a specific object type on your server.

·
enforces strict order in which it parses the names in the -Ndb _ name .owner _ name .table _ name .object _ name format. If you only provide three arguments, ddlgen assumes they are owner _ name , table _ name , and object _ name , in that order. Alternatively, you can also use -Nowner _ name .table _ name -Ddb _ name . ddlgen does not impose this restriction if object _ name is an index (I ).

-Ddbname

specifies the name of the database for the object you specify in the -N option. The default is the user’s default database.

-Xextended _ object _ type

differentiates the following:


user tables (OU ) from proxy tables (OD ) when you specify a table as your object type (-TU )
temporary databases (OD ) from nontemporary databases (OU ) when you specify database as your object type (-TDB )
SQLJ procedures (OD ) from stored procedures (OU ) when you specify procedure as your object type (-TP ).

If object _ type (-T ) is U (table) and -X is not specified, ddlgen generates DDL for both user tables and proxy tables. To generate DDL only for:


user tables – use the OU extended object type with the -X option.
proxy tables – use the OD extended object type with the -X option.

ddlgen does not support schema generation for system tables.

 

-Ooutput _ file

specifies an output file for the generated DDL. If you do not specify -O , the DDL you create appears in a console window.

-Eerror _ file

specifies a log file for recording errors. If you do not specify -E , the generated errors appear in a console window.

-Lprogress _ log _ file

specifies a log file for recording the progress of ddlgen . If you do not specify -L , the progress is not recorded.

-Jclient _charset

specifies the character set to use on the client. -Jclient _charset requests that Adaptive Server convert to and from client _charset , the character set used on the client. A filter converts input between client _charset and the Adaptive Server character set.

Omitting -J sets the character set to a default for the platform. The default may not necessarily be the character set that the client is using.

HP platforms – You must use -Jiso_1 to specify the correct character set.

-F

filters out indexes, triggers, and constraints out of table and database definitions in the DDL of table- and database-level objects. The valid filters are:


For tables [ % | I | RI | KC | TR | PC ]


For databases [ % | SGM | GRP | USR | R | D | UDD | U | V | P | XP | I | RI | KC | TR]

The filter options are:

 

 

Filter option  Filters out: 
%  Everything, and retrieves the schema-only definition of a database or table.
SGM  Segments
GRP  Groups
USR  Users
R  Rules
D  Defaults
UDD  Uer-defined datatypes
U  User tables
V  Views
P  Stored procedures
PC  Partition condition
XP  Extended stored procedures
I  Indexes
RI  Referential integrity constraints
KC  Primary- and unique-key constraints
TR  Triggers

 

-v

displays the version and copyright message of ddlgen and returns to the operating system.

 

Examples

Example 1

Caches – Generates DDL for a cache called default data cache on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TC -N"default data cache"

To generate DDL for all caches:

ddlgen -Ulogin -Ppassword -Sserver :port -TC -N%

Example 2

Defaults – Generates DDL for a default called “phondflt” owned by jones in the pubs2 database on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TD -Njones.phonedflt -Dpubs2

Alternatively, because ddlgen allows you to use a fully qualified name in the -N flag, you can omit the -Ddbname and include the database name in the -N option:

ddlgen -Ulogin -Ppassword -Sserver :port -TD -Ndbname .owner .defaultname

To generate DDL for all defaults in a database owned by “owner”:

ddlgen -Ulogin -Ppassword -Sserver :port -TD -Nowner .% -Ddbname

Example 3

Databases – Generates DDL for a database called pubs2 on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TDB -Npubs2

If you do not specify a dbname , ddlgen generates DDL for the default database of login :

ddlgen -Ulogin -Ppassword -Sserver :port

If you do not use the -T parameter, ddlgen generates DDL for a default-type database:

ddlgen -Ulogin -Ppassword -Sserver :port -Ndbname

To generate DDL for all databases:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -N%

Example 4

Database device – Generates DDL for a database device called master running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TDBD -Nmaster

To generate DDL for all database devices:

ddlgen -Ulogin -Ppassword -Sserver :port -TDBD -N%

Example 5

Temporary databases – Generates DDL for all databases, including tempdb :

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -N%

To generate DDL for all temporary databases, use the OD extended database type:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -XOD -N%

Although you can use the OD extended type in Adaptive Server versions 12.5.0.3 and later, versions earlier than 12.5.0.3 issue warning messages. You can safely ignore this message; ddlgen continues processing the command.

To generate DDL for all databases except temporary databases, use the OU extended type:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -XOU -N%

The following generates DDL for a temporary database named tempdb1 :

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -Ntempdb1

The output includes the following:

·
A create temporary database statement


create temporary database tempdb1 on master = 4,asdas = 2
go


An sp_tempdb bind statement where the isql application is bound to tempdb1 :


sp_tempdb 'bind','ap', 'isql', 'DB', 'tempdb1'
go

 

DDL for objects such as views, stored procedures, and tables is not generated along with DDL for a temporary database because these objects are temporary, and are re-created when the server restarts.

When you use the -F parameter to filter a table while generating DDL for a database object, then indexes, referential integrity, key constraints and triggers automatically get filtered, as they are a subset of the table object.

Example 6

Dump device – generates DDL for a dump device called tapedump1 running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TDPD -Ntapedump1

To generate DDL for all dump devices:

ddlgen -Ulogin -Ppassword -Sserver :port -TDPD -N%

Example 7

Execution class – generates DDL for an execution class called EC2 running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TEC -NEC2

To generate DDL for all execution classes:

ddlgen -Ulogin -Ppassword -Sserver :port -TEC -N%

Example 8

Engine groups – generates DDL for an engine group called LASTONLINE running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TEG -NLASTONLINE

To generate DDL for all engine groups:

ddlgen -Ulogin -Ppassword -Sserver :port -TEG -N%

Example 9

Extended stored procedures – generates DDL for the xp_cmdshell extended stored procedure in the pubs2 database, owned by Jones and running on a machine named HARBOR using port 1955, by using the fully qualified dbname .owner .extendedstoredprocedure format with the -N option:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TXP -Npubs2.jones.xp_cmdshell

Alternatively, you can use the -D option instead of using the fully qualified name:

ddlgen -Ulogin -Ppassword -Sserver :port -TXP

    -Nowner .extendedstoredprocedure -Ddbname

To generate DDL for all extended stored procedures:

ddlgen -Ulogin -Ppassword -Sserver :port -TXP -Ndbname .owner .%

Example 10

Filters – Generates DDL for the authors table in the pubs2 database, filtering for all indexes (I ), and referential integrity constraints (RI ), primary and unique key constraints (KC ), triggers (TR ), and partition condition (PC ) from the DDL of a table:

ddlgen -Uroy -Proy123 -TU -Nauthors -Dpubs2 -F%

Alternatively, you can specify each of the filters individually:

ddlgen -Ulogin -Ppassword -TU -Ndbname .owner .table

    -FI,RI,KC,TR

The following generates the definition of table _ name while filtering out foreign keys and primary-unique keys:

ddlgen -Ulogin -Ppassword -TU -Ntable_name -Ddbname

    -FRI,KC

Both of these generate foreign keys for a specified user in the entire database:

ddlgen -Ulogin -Ppassword -TRI -N%.%.% -Ddbname

Or:

ddlgen -Ulogin -Ppassword -TRI -Ndbname %.%.%

Both of these generate DDL for the primary and unique keys of all the tables in a database that begin with “PK”:

ddlgen -Ulogin -Ppassword -TKC -Ndbname .%.%.PK%

Or:

ddlgen -Ulogin -Ppassword -TKC -N%.%.PK% -Ddbname

The following generates schema-only definition of a database:

ddlgen -Ulogin -Ppassword -Sserver :port -TF -Ndbname -F%

Alternatively, you can specify each of the filters individually:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -Ndbname

    -FSGM,GRP,USR,R,D,UDD,V,P,XP,I,RI,KC,TR

The following generates the database DDL skipping the compiled object:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -Ndbname -FTR,D,XP,V,R

The following generates database definition without a table definition:

ddlgen -Ulogin -Ppassword -Sserver :port -TDB -Ndbname

    -FU

Example 11

Groups – Generates DDL for a group called “public” in the pubs2 database, running on a machine named HARBOR using port 1955, by using the fully qualified dbname .groupname format in the -N option:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TGRP -Npubs2.public

Alternatively, you can use the -D option to specify the dbname :

ddlgen -Ulogin -Ppassword -Sserver :port -TGRP -Ngroupname -Ddbname

To generate DDL for all groups:

ddlgen -Ulogin -Ppassword -Sserver :port -TGRP -Ndbname .%

Example 12

Indexes – Generates DDL for an index called au_lname for the table authors owned by dbo, in the pubs2 database:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TI -Ndbo.authors.au_lname -Dpubs2

Alternatively, because ddlgen allows you to use a fully qualified name in the -N flag, you can omit the -Ddbname and include the database name in the -N option:

ddlgen -Ulogin -Ppassword -Sserver :port

    -TI -Ndbname .owner .tablename .indexname

If you use a fully qualified name, you may omit the -D option.

To generate DDL for all indexes for a single table:

ddlgen -Ulogin -Ppassword -Sserver :port -TI

    -Ndbname .owner .tablename .%

To generate DDL for all indexes of all tables in a database:

ddlgen -Ulogin -Ppassword -Sserver :port -TI

    -Ndbname .%.%.%

For example, this generates DDL for all indexes for all tables in the pubs2 database:

ddlgen -Usa -P -SHARBOR:1955 -TI -Npubs2.%.%.%

 

ddlgen -Usa -P -SHARBOR:1955 -TI -Npubs2.%.%.%

Example 13

Keys – Both of these generate DDL for the primary and unique keys of all the tables in a database that begin with “PK”:

ddlgen -Usa -P -TKC -Ndbname .%.%.PK%

Or:

ddlgen -Usa -P -TKC -N%.%.PK% -Ddbname

Example 14

Logical keys LK generates logical keys of table defined by sp_primarykey , sp_commonkey , sp_foreignkey statements. Since these keys do not have a name, the name of the object in this case would be the name of the table. This example generate a DDL for logical keys of table authors in database pubs2 running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TLK -Npubs2.dbo.authors

To generate DDL for all logical keys in database pub2 use:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TLK -Npubs2.%.%

To filter out logical keys definition from DDL of table authors use LK in -F argument, use:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TLK -Npubs2.dbo.authors -FLK

Example 15

Logins – Generates DDL for all logins on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TL -N%

The password in the DDL generated for all logins is “password”.

Alternatively, you can specify an individual login by using -Nusername instead of -N% :

ddlgen -Ulogin -Ppassword -Sserver :port -TL -Nusername

Example 16

Remote Servers – Generates DDL for a remote server called ORANGE on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TRS -NORANGE

To generate DDL for all remote servers:

ddlgen -Ulogin -Ppassword -Sserver :port -TRS -N%

Example 17

Roles – Generates DDL for the sa _ role on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TRO -Nsa_role

To generate DDL for all roles:

ddlgen -Ulogin -Ppassword -Sserver :port -TRO -N%

The password in the DDL generated for all roles is “password”.

Example 18

Rules – Generates DDL for all rules associated with authors on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TR -Nauthors.dbo.%

The % symbol tells ddlgen to create DDLs for all rules that exist on the server.

You can also give the fully qualified name of the rule:

ddlgen -Ulogin -Ppassword -Sserver :port -TR -Ndbname .owner .rulename

Alternatively, you can also use the -D parameter:

ddlgen -Ulogin -Ppassword -Sserver :port -TR -Nowner .rulename -Ddbname

Example 19

Segments – Generates DDL using the fully qualified dbname .segmentname format in the -N option for a segment called logsegment for the pubs2 database, on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TSGM -Npubs2.logsegment

Alternatively, you can use specify the dbname using the -D option:

ddlgen -Ulogin -Ppassword -Sserver :port -TSGM -Nsegmentname -Ddbname

To generate DDL for all segments:

ddlgen -Ulogin -Ppassword -Sserver :port -TSGM -Ndbname .%

Example 20

SQLJ functions – Generates DDL for a SQLJ function named region _ of owned by dbo in database master :

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TF –Nmaster.dbo.region_of

Alternatively you can also use the -D parameter:

ddlgen -Ulogin -Ppassword -Sserver :port -TF –Ndbo.region_of –Dmaster

To generate DDL for all SQLJ functions in a database, use object type F :

ddlgen -Ulogin -Ppassword -Sserver :port -TF –Ndbname .owner .%

Example 21

SQLJ procedures – are a kind of stored procedure. You generate DDL for SQL procedures along with DDL for stored procedures. The following generates DDL for all stored procedures—including SQLJ procedures—owned by dbo in the master database:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TP –Nmaster.dbo.%

To generate DDL for all SQLJ procedures that are only owned by dbo in the master database, use the following, where the extended type OD refers to SQLJ procedures:

ddlgen -Ulogin -Ppassword -Sserver :port -TP –Nmaster.dbo.% -XOD

To generate DDL for all procedures except SQLJ procedures owned by dbo in the master database, use the following, where the extended type OU refers to all stored procedures except SQLJ procedures:

ddlgen -Ulogin -Ppassword -Sserver :port -TP –Nmaster.dbo.% -XOU

Example 22

Stored procedures – Generates DDL for the sp_monitor stored procedure for the pubs2 database on a machine named HARBOR using port 1955, using the fully qualified dbname .owner .procedure _ name format for the -N option:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TP -Npubs2.dbo.sp_monitor

Alternatively, you can use specify the dbname using the -D option:

ddlgen -Ulogin -Ppassword -Sserver :port -TP -Nowner .procedurename -Ddbname

To generate DDL for all stored procedures:

ddlgen -Ulogin -Ppassword -Sserver :port -TP -Ndbname .owner .%

Example 23

Tables – Generates DDL for all user tables in the pubs2 database owned by “dbo” and running on a machine named HARBOR using port 1955:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TU -Ndbo.% -Dpubs2

You can also use the -N parameter to give the fully qualified name of the table:

ddlgen -Ulogin -Ppassword -Sserver :port -TU

    -Ndbname .tableowner .tablename

Alternatively, you can also use the -D parameter to specify the database:

ddlgen -Ulogin -Ppassword -Sserver :port -TU

    -Ntableowner .tablename -Ddbname

To generate DDL for all proxy tables, which uses the value OD , use -XOD instead, where X is the extended type, and OD denotes proxy tables:

ddlgen -Ulogin -Ppassword -Sserver :port -TU

    -Ntableowner .% -Ddbname -XOD

To generate DDL for all user tables, which uses the value OU , use -XOU instead, where X is the extended type, and OU denotes user tables:

ddlgen -Ulogin -Ppassword -Sserver :port -TU

    -Ntableowner .% -Ddbname -XOU

To generate DDL for all tables, including user tables and proxy tables:

ddlgen -Ulogin -Ppassword -Sserver :port -TU -Ndbname .tableowner .%

Example 24

Triggers – Generates DDL for the trigger checksum for the pubs2 database on a machine named HARBOR using port 1955, using the fully qualified dbname .owner .trigger _ name format for the -N option:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TTR -Npubs2.dbo.checksum

Alternatively, you can use specify the database _ name using the -D option:

ddlgen -Ulogin -Ppassword -Sserver :port -TTR

    -Nowner .triggername -Ddbname

To generate DDL for all triggers:

ddlgen -Ulogin -Ppassword -Sserver :port -TTR -Ndbname .owner .%

 

Example 25

User-defined datatypes – Generates DDL for the user-defined datatype “Identype” for the pubs2 database on a machine named HARBOR using port 1955 using the fully qualified dbname .userdefined _ datatype format for the -N option:

ddlgen -Uroy -Proy123 -SHARBOR:1955 -TUDD -Npubs2.Identype

Alternatively, you can use the -D option to specify the dbname :

ddlgen -Ulogin -Ppassword -Sserver :port -TUDD

    -Nuserdefined_datatype -Ddbname

To generate DDL for all user-defined datatypes:

ddlgen -Ulogin -Ppassword -Sserver :port -TUDD -Nbname .%

For example, this generates DDL for all indexes for all tables in the pubs2 database Usage


ddlgen does not identify existing sequences within views, stored procedures or triggers. For this reason, when generating DDL for a database, you must first run ddlgen on those views, stored procedures and triggers that are independent, before running ddlgen on those with dependencies. For example, if view B depends on view A, you must first run ddlgen on view A, before running it on view B.


The default information for ddlgen is:

 

 

Option  Parameter  Required  Default 
-U  username  Yes None
-P  password  Yes None
-S  host _ name :port _ number  Yes None
-T  object _ type  No Database
       
  See the -T parameter description for a list of valid object types    
-N  object _ name  Yes, if object _ type for -T is not DB (database) Default database name of username , if -Tobject _ type is db or if -T is not specified
-D  database _ name  No Default database of username 
-X  extended _ object _ type  No; use only when the object _ type for -T is U (user table), P (procedure), DB (database) None
       
  Options are:    
       
  o    
  OU – for user tables, user databases (excluding temporary databases), and stored procedures (excluding SQLJ procedures).    
       
  o    
  OD – for proxy tables, temporary databases, and SQLJ procedures.    
-O  output _ file _ name  No Standard out
-E  error _ file _ name  No Standard out
-L  log _ file _ name  No None
-V  version _ number of ddlgen  No None

 

 

At the command line, invoke ddlgen using the ddlgen shell script file ( ddlgen.bat for Windows), included in your Adaptive Server installation. The main class in DDLGen.jar is com.sybase.ddlgen.DDLGenerator .


To start ddlgen in the Sybase Central plug-in for Adaptive Server:

a.Right-click on the object for which you want to generate DDL.

b.Select Generate DDL .


In the output DDL of create table , bind statements are generated as independent DLL instead of dependent DLL.

 

Filters

If you use an invalid filter parameter, ddlgen generates a warning, ignores that parameter, and continues with the rest of the valid parameters you specify.

If you specify % along with other filter parameters, ddlgen ignores all other filterable parameters, and only shows schema-only definitions. ddlgen then continues to evaluate the dependencies within the subset of the applied as the filterable parameters for the database.

Permissions

Since ddlgen needs to obtain data from system catalogs, users must either be logged in as “dbo” or have select permissions on syscatalogs .

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:ddlgen 表结构
————————————————————————————————-

在用isql连接数据 库的时候,比较常见的错误有:服务 没启动报错,报密码错误,报服务名不存在。
分别为:

1.服务名不存在:

CT-LIBRARY error:
        ct_connect(): directory service layer: internal directory control layer error: Req
uested server name not found.


2.服务没有启动:

CT-LIBRARY error:
        ct_connect(): network packet layer: internal net library error: Net-Lib protocol d
river call to connect two endpoints failed


3.密码错误:

Msg 4002, Level 14, State 1:
Server 'TEST':
Login failed.
CT-LIBRARY error:
        ct_connect(): protocol specific layer: external error: The attempt to connect to t
he server failed.

在执行isql命令连接数据库 的时候,报密码错误和服务名称不存在这两个错误的情况下,反映很快。也就是说:在isql命令行后敲入回车后很快就给你提示服务名不存在或密码错误。
但是在报因服务没有启动导致的错误时,要等一段时间才有结果。因为 isql 需要等待 ASE 服务器的响应。

连接sybase数据库的时候将依次尝试sql.ini文件 中相应服务名下面的所有监听信息。如果所有的监听信息都连接失败后,才给出无法连接的提示信息。

sybase尝试连接一个监听地址端口需要花费多长时间?失败后将继续尝试几次? 以后再总结。

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字: ASE isql login two endpoints failed 连接失败情况
————————————————————————————————-

此篇为对以前的问题的整理。

solaris 10 64-bit上安装Sybase15.0.3 ESD#1,程序安装好了后用资源文件 resource-files来创建服务 。但是老是报不能创建共享内存 的错误。
Solaris环境为: 
Sun OS 5.10 Generic_127111-11 sun4v sparc SUNW,SPARC-Enterprise-T5120
16G内存,64核CPU

共享内存已经配置为如下,故没有调整。

root@SERVER # more /etc/system | grep shm
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=100
set shmsys:shminfo_shmseg=10
set shmsys:shminfo_shmmax=4294967295
*               exclude: sys/shmsys
set shmsys:shminfo_shmmax=10294967295
set shmsys:shminfo_shmmin=1
* set shmsys:shminfo_shmmni=100
* set shmsys:shminfo_shmseg=10
*       set shmsys:shminfo_shmmax = 268435456
*       set shmsys:shminfo_shmseg = 1024
*       set shmsys:shminfo_shmmni = 1024
        set shmsys:shminfo_shmmni = 4096

其中曾经重启过一次服务器

但是用资源文件创建服务时,srvbuildres -I /app/sybase/interfaces -r /app/sybase/srvbuild-adaptiveserver.res
一直下面的报错。

-bash-3.00$ more srvbuild0111.017
Mon Jan 11 22:55:57 2010: srvbuild/15.0.3 ESD #1/P/Sun_svr4/SunOS 5.8/EBF 16556/OPT/Mon Ma
r  9 02:14:53 PDT 2009
Mon Jan 11 22:55:57 2010: Getting attribute values from sybinit resource file `/app/sybase
/srvbuild.adaptive_server.rs'.
Mon Jan 11 22:55:57 2010:
Mon Jan 11 22:55:57 2010:
Mon Jan 11 22:55:57 2010:
Mon Jan 11 22:55:57 2010:
type = 1
application_type = MIXED
server_page_size = 4k
master_device_physical_name = /app/sybdata/master.dat
master_device_size = 200
master_database_size = 160
sybsystemprocs_device_physical_name = /app/sybdata/rsystemprocs.dat
sybsystemprocs_device_size = 200
sybsystemprocs_database_size = 200
errorlog = /app/sybase/ASE-15_0/install/SYBASE.log
configfile = /app/sybase/ASE-15_0/SYB_XXXX_TEST.cfg
sybsystemdb_device_physical_name = /app/sybdata/rsystemdb.dat
sybsystemdb_device_size = 20
sybsystemdb_database_size = 20
tempdb_device_physical_name = /app/sybdata/tempdbdev.dat
tempdb_device_size = 100
tempdb_database_size = 100
shmem = /app/sybase/ASE-15_0
default_backup_server = SYB_XXXX_TEST_BS
ifiledir = /app/sybase
addl_cmdline_parameters =
do_configure_pci = no
sybpcidb_device_physical_name = PUT_THE_PATH_OF_YOUR_SYBPCIDB_DATA_DEVICE_HERE
sybpcidb_device_size = 48
sybpcidb_database_size = 48
server_name = SYB_XXXX_TEST
force_buildmaster = no
do_optimize_config = no
Mon Jan 11 22:55:57 2010: (Shell command) /app/sybase/ASE-15_0/bin/dataserver -d/app/sybda
ta/master.dat -b200M -z4k -sSYB_XXXX_TEST -e/app/sybase/ASE-15_0/install/SYBASE.log -T1623
> /tmp/sbAAAjCaGrf 2>&1
dataserver: master device size for this server: 200.0 Mb
dataserver: master database size for this server: 26.0 Mb
dataserver: model database size for this server: 6.0 Mb
00:00000:00000:2010/01/11 22:55:57.87 kernel  SySAM: Using licenses from: /app/sybase/SYSA
M-2_0/licenses
00:00000:00000:2010/01/11 22:55:57.96 kernel  SySAM: Checked out license for 1 ASE_CORE (2
009.1231/permanent/19B3 47BC 0B7E 8DC3).
00:00000:00000:2010/01/11 22:55:57.96 kernel  This product is licensed to: ASE Developer E
dition - For Development and Test use only
00:00000:00000:2010/01/11 22:55:57.96 kernel  Checked out license ASE_CORE
00:00000:00000:2010/01/11 22:55:57.96 kernel  Adaptive Server Enterprise (Developer Editio
n)
00:00000:00000:2010/01/11 22:55:57.97 kernel  Initializing device /app/sybdata/master.dat
from offset 0 with zeros.
00:00000:00000:2010/01/11 22:56:00.46 kernel  Finished initialization.
00:00000:00000:2010/01/11 22:56:00.47 kernel  Using config area from primary master device
.
00:00000:00000:2010/01/11 22:56:00.47 server  Configuration Error: Configuration file, '/a
pp/sybase/SYB_XXXX_TEST.cfg', does not exist.
00:00000:00000:2010/01/11 22:56:00.66 kernel  Warning: A configuration file was not specif
ied and the default file '/app/sybase/SYB_XXXX_TEST.cfg' does not exist. ASE creates the d
efault file with the default configuration.
00:00000:00000:2010/01/11 22:56:00.68 kernel  Warning: Using default file '/app/sybase/SYB
_XXXX_TEST.cfg' since a configuration file was not specified. Specify a configuration file
name in the RUNSERVER file to avoid this message.
00:00000:00000:2010/01/11 22:56:00.69 kernel  os_create_region: can't allocate 70795264 by
tes

00:00000:00000:2010/01/11 22:56:00.69 kernel  kbcreate: couldn't create kernel region.
00:00000:00000:2010/01/11 22:56:00.69 kernel  kistartup: could not create shared memory
Mon Jan 11 22:56:00 2010: Buildmaster return code: 0.
sybdata/master.dat -e/app/sybase/ASE-15_0/install/SYBASE.log -c/app/sybase/ASE-15_0/SYB_XXXX_TEST.cfg -M/app/sybase/ASE-15_0 -i/app/sybase -sSYB_XXXX_TEST -T1623 > /dev/null 2>&1
-bash-3.00$

是共享内存的问题吗?我不是已经按照安装文档上的说明修改了solaris的共享内存了吗?

后来,经过咨询solaris工程师,原来是solaris10和以前的solaris9在共享内存上有些不同。solaris10修改了共享内存方式,针对用户级别可以设置用户所能共享的内存段。

为sybase用户在项目数据库中添加一条记录,命令如下:

projadd -U sybase -p 1233 -c "sybase parameters" user.sybase
projmod -sK "project.max-shm-memory=(priv,6G,deny)" user.sybase
projmod -sK "project.max-sem-ids=(priv,100,deny)" user.sybase
projmod -sK "process.max-sem-nsems =(priv,256,deny)" user.sybase

另外,可以查看文件/etc/project来检查上面的配置是否生效。

修改完之后,再次执行srvbuildres命令创建sybase主服务,成功!

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:ASE solaris 10 shared memory projadd 共享内存 couldn't create kernel region
————————————————————————————————-

在oracle中显示分页很简单, 利用两次rownum就实现了。

下面的语句用来返回DBA_OBJECTS表中类型为TABLE的所有记录中的第100行至第200行。

select * from
( select rownum rnm, a.* from ( select OBJECT_NAME from DBA_OBJECTS where object_type='TABLE' ) a
    where rownum <= 200 )
where rnm > 100

执行结果为:

SQL> select * from
  2  ( select rownum rnm, a.* from ( select OBJECT_NAME from DBA_OBJECTS where object_type='TABLE' ) a
  3      where rownum <= 200 )
  4  where rnm > 100
  5  ;
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       101 HISTGRM$
       102 HIST_HEAD$
       103 DUAL
       104 PARTOBJ$
       105 PARTCOL$
       106 TABPART$
       107 INDPART$
       108 SUBPARTCOL$
       109 TABSUBPART$
       110 INDSUBPART$
       111 TABCOMPART$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       112 INDCOMPART$
       113 PARTLOB$
       114 LOBFRAG$
       115 LOBCOMPPART$
       116 DEFSUBPART$
       117 DEFSUBPARTLOB$
       118 SYSTEM_PRIVILEGE_MAP
       119 TABLE_PRIVILEGE_MAP
       120 STMT_AUDIT_OPTION_MAP
       121 RESOURCE_MAP
       122 USER_ASTATUS_MAP
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       123 EXPACT$
       124 NOEXP$
       125 PROCEDUREJAVA$
       126 PROCEDUREC$
       127 PROCEDUREPLSQL$
       128 RESULT$
       129 KOTTD$
       130 KOTTB$
       131 KOTAD$
       132 KOTMD$
       133 KOTTBX$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       134 KOTADX$
       135 KOPM$
       136 VTABLE$
       137 ATEMPTAB$
       138 LIBRARY$
       139 USER_HISTORY$
       140 MIGRATE$
       141 ICOLDEP$
       142 OPERATOR$
       143 OPBINDING$
       144 OPANCILLARY$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       145 OPARG$
       146 INDTYPES$
       147 INDOP$
       148 INDARRAYTYPE$
       149 SECOBJ$
       150 ASSOCIATION$
       151 USTATS$
       152 JAVASNM$
       153 SUM$
       154 SUMDETAIL$
       155 SUMINLINE$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       156 SUMKEY$
       157 SUMAGG$
       158 SUMJOIN$
       159 SUMDEP$
       160 SUMPRED$
       161 SUMQB$
       162 DIM$
       163 DIMLEVEL$
       164 DIMLEVELKEY$
       165 DIMJOINKEY$
       166 DIMATTR$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       167 HIER$
       168 HIERLEVEL$
       169 RLS$
       170 RLS_SC$
       171 RLS_GRP$
       172 RLS_CTX$
       173 CONTEXT$
       174 RULESET$
       175 INDPART_PARAM$
       176 OL$
       177 OL$HINTS
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       178 OL$NODES
       179 SQL$
       180 SQL$TEXT
       181 SQLPROF$
       182 SQLPROF$DESC
       183 SQLPROF$ATTR
       184 EXPPKGOBJ$
       185 EXPPKGACT$
       186 EXPDEPOBJ$
       187 EXPDEPACT$
       188 MON_MODS$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       189 MON_MODS_ALL$
       190 METAVIEW$
       191 METAFILTER$
       192 METAXSL$
       193 METAXSLPARAM$
       194 METASTYLESHEET
       195 METASCRIPT$
       196 METASCRIPTFILTER$
       197 METANAMETRANS$
       198 METAPATHMAP$
       199 EXTERNAL_TAB$
       RNM OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------
       200 EXTERNAL_LOCATION$
已选择100行。
SQL>

 

总结:在oracle中利用rownum产生伪列真的是太方便了, 尤其利用派生表再加上伪列可以写出很复杂的sql语句来。

比ASE和IQ的实现方式强N倍。 哎,可叹的sybase啊。

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:oracle 分页 rownum
————————————————————————————————-

接上篇的关于MySQL中的分页方法,本篇简单讨论在Sybase ASE中实现数据结果分页的方式。

本篇介绍三种方法。

第一种:利用游标

程序开发人员比较喜欢使用游标,因为游标的“循环”遍历方式类似编程语言中的for,while,loop语句的实现方法,写起来比较容易。使用游标一般步骤是:为指定的SQL语句定义一个游标,打开并移动游标,当移动到指定行号的记录行之后,再按照需要提取的行数来取数据。从表面上看解决了提取指 定范围数据的问题;但是在实际应用上,有可能会出现严重的性能问题。建立游标需要耗用一定的系统资源之外;当表内的数据量有上千万甚至到亿级别并且需要取大量的数据结果时,用游标每移动一 次就取这行数据,然后再移动游标,这个过程将是缓慢的。在使用游标的过程中,系统会给相应的表加上共享锁,导致锁竞争而严重影响数据库的性能。

在此不再介绍游标的实现方式,此法比较简单。一个使用游标分页的例子:sp_splitpage_by_cursor.sql

第二种:利用临时表和标志列

在Sybase ASE12.5.3及以后的版本中,我们可以用top关键字来限定只返回结果集的前N行数据。在ASE12.5.3之前的版本中只能用set rowcount N 的方法来“曲线救国”了。

对于取结果集的第N行至第N+M行数据的要求,我们考虑利用top来实现的话,比较容易想到的是:执行两次top,再加一次倒序排序。

步骤如下:

          (1) select top N+M * from table_name where_clause order by ID ASC     --把此结果集派生为表:table_name1

                  (2)   select top M * from table_name1 order by ID  DESC                          --把此结果集派生为表:table_name2

                  (3)   select * from table_name2 order by ID  ASC

上面的3条语句好像能够实现返回第N行至第N+M行数据的要求。但是,在Sybase ASE中仅仅利用派生表而不利用临时表是不能实现这个要求的。

仅仅是ASE中的“派生出派生表(derived table)的SQL语句中不能含有order by 子句”这个限制就足以使上面的方法行不通。还有一个限制是,上面的3个步骤中都利用ID列进行排序。如果表中没有可用的排序列时,那么上述方法也不能用 了。不过幸运的是,一般要求对其结果集进行分页的表都是有可以用作排序的列的(数字型或者日期型)。

继续寻找一个能用的方法,下面着重介绍目前通用的ASE的分页思路。此思路的关键是产生identity自增列和临时表。

在ASE中大家要是找到了不用临时表就可以实现分页的方法请麻烦告诉我一声。 我尝试了很多次,都不是很理想。

概括起来主要语句有两条:

                (1)   select syb=identity(10),*  into #temp_table from table_name where_clause   order_by_clause

                (2)   select  * from #temp_table where_clause and syb >= N   and syb <= N+M

使用此方法实现ASE分页的一个存储过程为:

-- 此存储过程适用于所有版本的ASE中
use sybsystemprocs
go
if exists(select 1 from sybsystemprocs.dbo.sysobjects where type='P' and name='sp_page')
  drop procedure sp_page
go

create procedure sp_page @qry varchar(16384),@ipage int,@num int
as
begin
 
  declare @rcount int
  declare @execsql varchar(16384)
 
  select @rcount=@ipage*@num
  set @execsql = 'set rowcount '|| convert(varchar,@rcount)
  set @execsql = @execsql || stuff(@qry,charindex('SELECT ',upper(@qry)),6,' SELECT sybid=identity(12),')
  set @execsql = stuff(@execsql,charindex(' FROM ',upper(@execsql)),6,' INTO #temptable FROM ')
  set @execsql = @execsql || ' SELECT * FROM #temptable  WHERE sybid >' || convert(varchar,(@ipage-1)*@num)
  set @execsql = @execsql || ' AND sybid<=' || convert(varchar,@ipage*@num) + ' set rowcount 0'
  execute(@execsql)
 
end
go

exec sp_procxmode 'sp_page',anymode
go
grant execute on sp_page to public
go

用一个例子演示一下:

(1) 建立测试表:testA

create table testA(id int not null,name varchar(30) null)
go

(2) 插入测试数据

insert into testA
select 1,'liuzhenfu'
go
insert into testA
select 2,'andkylee'
go

(3) 循环插入大量的重复数据

insert into testA
select id+(select max(id) from testA),name from testA
go 15

向表testA循环插入已有的数据,15次之后,表testA内的数据达到2^16 = 65536 行。

 

(4) 利用临时表 + 自增标志列来提取第100行至第200行的数据。

语句如下:

select syb=identity(10) ,* into #tempA from testA
select * from #tempA where syb>=100 and syb<=200
drop table #tempA

返回的结果为:

1> select syb=identity(10),* into #tempA from testA
2> select * from #tempA where syb>=100 and syb<=200
3> go
(65536 rows affected)
 syb           id          name
 ------------- ----------- ---------------------------
           100         100 andkylee
           101         101 liuzhenfu
           102         102 andkylee
           103         103 liuzhenfu
           104         104 andkylee
           105         105 liuzhenfu
           106         106 andkylee
           107         107 liuzhenfu
           108         108 andkylee
           109         109 liuzhenfu
           110         110 andkylee
           111         111 liuzhenfu
           112         112 andkylee
           113         113 liuzhenfu
           114         114 andkylee
           115         115 liuzhenfu
           116         116 andkylee
           117         117 liuzhenfu
           118         118 andkylee
           119         119 liuzhenfu
           120         120 andkylee
           121         121 liuzhenfu
           122         122 andkylee
           123         123 liuzhenfu
           124         124 andkylee
           125         125 liuzhenfu
           126         126 andkylee
           127         127 liuzhenfu
           128         128 andkylee
           129         129 liuzhenfu
           130         130 andkylee
           131         131 liuzhenfu
           132         132 andkylee
           133         133 liuzhenfu
           134         134 andkylee
           135         135 liuzhenfu
           136         136 andkylee
           137         137 liuzhenfu
           138         138 andkylee
           139         139 liuzhenfu
           140         140 andkylee
           141         141 liuzhenfu
           142         142 andkylee
           143         143 liuzhenfu
           144         144 andkylee
           145         145 liuzhenfu
           146         146 andkylee
           147         147 liuzhenfu
           148         148 andkylee
           149         149 liuzhenfu
           150         150 andkylee
           151         151 liuzhenfu
           152         152 andkylee
           153         153 liuzhenfu
           154         154 andkylee
           155         155 liuzhenfu
           156         156 andkylee
           157         157 liuzhenfu
           158         158 andkylee
           159         159 liuzhenfu
           160         160 andkylee
           161         161 liuzhenfu
           162         162 andkylee
           163         163 liuzhenfu
           164         164 andkylee
           165         165 liuzhenfu
           166         166 andkylee
           167         167 liuzhenfu
           168         168 andkylee
           169         169 liuzhenfu
           170         170 andkylee
           171         171 liuzhenfu
           172         172 andkylee
           173         173 liuzhenfu
           174         174 andkylee
           175         175 liuzhenfu
           176         176 andkylee
           177         177 liuzhenfu
           178         178 andkylee
           179         179 liuzhenfu
           180         180 andkylee
           181         181 liuzhenfu
           182         182 andkylee
           183         183 liuzhenfu
           184         184 andkylee
           185         185 liuzhenfu
           186         186 andkylee
           187         187 liuzhenfu
           188         188 andkylee
           189         189 liuzhenfu
           190         190 andkylee
           191         191 liuzhenfu
           192         192 andkylee
           193         193 liuzhenfu
           194         194 andkylee
           195         195 liuzhenfu
           196         196 andkylee
           197         197 liuzhenfu
           198         198 andkylee
           199         199 liuzhenfu
           200         200 andkylee
(101 rows affected)

需要将select * from #tempA中的星号*替换为需要返回的列名。

继续。。。。

当要求返回满足name='andkylee'的所有行中的第100行至第200行的数据时, 利用

select syb=identity(10),* into #tempA from testA where name='andkylee'

select * from #tempA where syb>=100 and syb<=200

drop table #tempA

 

第三种:利用rowcount

此种方法有点不足:必须利用可用作排序的列 对结果集进行排序。

还是上面的测试表testA,如果从第9000行开始选择10行数据,那么语句如下:

declare @id1 int
set rowcount 9000
select @id1 = id from testA order by id
set rowcount 10
select *from testA where id >= @id1 order by id
set rowcount 0
go

 

此种方法中核心语句是select @id1=id from testA order by id , 在对表testA执行查询的过程中,每读取一行都会把id列的值赋给@id1这个变量,一直持续到最后一行,@id1这个变量反复被下一行的id值刷新, 最后结果只得到最后一行的id值。如果在此select语句之前加上rowcount的限定,那么就可用变量@id1来获得第rowcount行的id 值,于是我们也就获得了要返回的范围结果集的起点了。

后面的 set rowcount 10

         select * from testA where id >= @id1 order by id

这两句实际上可以用一句select top 10 * from testA where id >= @id1 order by id  来替代。 

这样,两种不同的实现形式为:

declare @id1 int
set rowcount 9000
select @id1 = id from testA  order by id
set rowcount 0
select top 10  *from testA where  id >= @id1 order by id
go

 

分别看看执行结果吧!

第一种方式的执行结果:

1> declare @id1 int
2> set rowcount 9000
3> select @id1 = id from testA order by id
4> set rowcount 10
5> select *from testA where id >= @id1 order by id
6> set rowcount 0
7> go
(9000 rows affected)
 id          name
 ----------- ------------------------------
        9000 andkylee
        9001 liuzhenfu
        9002 andkylee
        9003 liuzhenfu
        9004 andkylee
        9005 liuzhenfu
        9006 andkylee
        9007 liuzhenfu
        9008 andkylee
        9009 liuzhenfu
(10 rows affected)
1>
 

第二种方式的执行结果:

1> declare @id1 int
2> set rowcount 9000
3> select @id1 = id from testA order by id
4> set rowcount 0
5> select top 10  *from testA where id >= @id1 order by id
6> go
(9000 rows affected)
 id          name
 ----------- ------------------------------
        9000 andkylee
        9001 liuzhenfu
        9002 andkylee
        9003 liuzhenfu
        9004 andkylee
        9005 liuzhenfu
        9006 andkylee
        9007 liuzhenfu
        9008 andkylee
        9009 liuzhenfu
(10 rows affected)
1>

当然,两种结果一模一样。

最后我们测试表testA中的ID列顺序值打乱, 来看看以上语句的执行情况。执行:

update testA set id = id + cast( rand() * 65536 as int ) 

ID列值打乱之后,前100行的数据为:

1> select top 100 * from testA
2> go
 id          name
 ----------- ------------------------------
       51366 liuzhenfu
       33573 andkylee
       19447 liuzhenfu
       19408 andkylee
       57839 liuzhenfu
       18817 andkylee
     ......................
       19075 liuzhenfu
       17081 andkylee
       26444 liuzhenfu
        6620 andkylee
       52344 liuzhenfu
       49348 andkylee
(100 rows affected)

我们要求返回满足name='andkylee'的从第9000行开始的10行数据。

declare @id1 int
set rowcount 9000
select @id1 = id from testA where name='andkylee' order by id
set rowcount 10
select *from testA where name='andkylee' and id >= @id1 order by id
set rowcount 0
go

结果为:

1> declare @id1 int
2> set rowcount 9000
3> select @id1 = id from testA where name='andkylee' order by id
4> set rowcount 10
5> select *from testA where name='andkylee' and id >= @id1 order by id
6> set rowcount 0
7> go
(9000 rows affected)
 id          name
 ----------- ------------------------------
       48639 andkylee
       48639 andkylee
       48641 andkylee
       48641 andkylee
       48642 andkylee
       48643 andkylee
       48644 andkylee
       48644 andkylee
       48650 andkylee
       48650 andkylee
(10 rows affected)

如果不对ID列进行排序, 有下面的sql语句:

declare @id1 int
set rowcount 9000
select @id1 = id from testA where name='andkylee'
set rowcount 10
select *from testA where name='andkylee' and id >= @id1
set rowcount 0
go

相应的结果集为:

1> declare @id1 int
2> set rowcount 9000
3> select @id1 = id from testA where name='andkylee'
4> set rowcount 10
5> select *from testA where name='andkylee' and id >= @id1
6> set rowcount 0
7> go
(9000 rows affected)
 id          name
 ----------- ------------------------------
       74076 andkylee
       74514 andkylee
       74053 andkylee
       74385 andkylee
       74339 andkylee
       74792 andkylee
       74794 andkylee
       74984 andkylee
       75052 andkylee
       74138 andkylee
(10 rows affected)
1>

可以发现这个两句的结果是不同的。

我想既然都要求返回指定范围的结果集, 肯定是有排序的依据了, 否则怎么知道该返回哪个范围呢?

还有,我给出的第三种方法,在进行表扫描的时候,即使不指定排序,也是能够得到正确结果的。因为表扫描时很可能会按照表内数据在物理页面上的物理位置来返回结果。

就先介绍到这里吧, 后续可能会根据情况进行补充。

文件下载:

使用第二种方法在ASE实现分页的存储过程: sp_page.sql 包含top和set rowcount两种。

根据显示的当前页号进行优化处理、更通用些的存储过程:splitpage.sql

————————————————————————————————-
—- 本文为andkylee个人原创,请在尊重作者劳动成果的前提下进行转载;
—- 转载务必注明原始出处 : http://www.dbainfo.net
—- 关键字:ASE 分页  top  identity  set rowcount  temp table  自增列 伪列 临时表
————————————————————————————————-