Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » SQL Anywhere 服务器 - SQL 的用法 » SQL 方言和兼容性 » SQL 方言 » 为实现 Transact-SQL 兼容性配置数据库

 

为实现 Transact-SQL 兼容性设置选项

可以使用 SET OPTION 语句来设置 SQL Anywhere 数据库选项。有几项数据库选项设置与 Transact-SQL 的行为相关。

设置 allow_nulls_by_default 选项

缺省情况下,如果您没有显式定义新列允许 NULL,Adaptive Server Enterprise 就不允许新列中出现 NULL。SQL Anywhere 在缺省情况下允许在新列中出现 NULL,这符合 SQL/2003 ISO 标准。

要使 Adaptive Server Enterprise 以符合 SQL/2003 的方式运行,请使用 sp_dboption 系统过程将 allow_nulls_by_default 选项设置为 true。

要使 SQL Anywhere 以与 Transact-SQL 兼容的方式运行,请将 allow_nulls_by_default 选项设置为 Off。如下使用 SET OPTION 语句就可以达到这一目的:

SET OPTION PUBLIC.allow_nulls_by_default = 'Off';
设置 quoted_identifier 选项

缺省情况下,Adaptive Server Enterprise 处理标识符和字符串的方式与 SQL Anywhere 有所不同,后者符合 SQL/2003 ISO 标准。

quoted_identifier 选项在 Adaptive Server Enterprise 和 SQL Anywhere 中均可用。为了以兼容的方式处理标识符和字符串,应确保在这两种数据库中将该选项设置为相同的值。请参见quoted_identifier 选项 [兼容性]

要想获得 SQL/2003 行为,请在 Adaptive Server Enterprise 和 SQL Anywhere 中均将 quoted_identifier 选项设置为 On。

要想获得 Transact-SQL 行为,请在 Adaptive Server Enterprise 和 SQL Anywhere 中均将 quoted_identifier 选项设置为 Off。如果您选择此设置,则不能在双引号中使用与关键字相同的标识符。作为将 quoted_identifier 设置为 Off 的替代选择,确保将在应用程序的 SQL 语句中使用的所有字符串括在单引号而不是双引号中。

设置 string_rtruncation 选项

Adaptive Server Enterprise 和 SQL Anywhere 都支持 string_rtruncation 选项,该选项会影响在 INSERT 或 UPDATE 字符串被截断时所报告的错误消息。请确保在每种数据库中将该选项设置为相同的值。请参见string_rtruncation 选项 [兼容性]

请参见兼容性选项