2017-08-17 61 views
0

我在AWS RDS SQL Server数据库中遇到了奇怪的问题,但我无法弄清楚发生了什么。关于Amazon RDS SQL Server的ANSI警告未设置

试验1个

create table #tmp 
(test varchar(10) null) 

insert into #tmp 
select 'asfsadfasdsafdafas' 

select * from #tmp 
drop table #tmp 

结果:

消息8152,级别16,状态14,行5
字符串或二进制数据将被截断。

------------------ 
asfsadfasd 

当我看到数据库的属性,它说的是ANSI:在

(0行(S)的影响)

测试2

set ANSI_WARNINGS OFF 

create table #tmp1 
(test varchar(10) null) 

insert into #tmp1 
select 'asfsadfasdsafdafas' 

select * from #tmp1 
drop table #tmp1 

结果警告已启用设置为FALSE,但是,数据库似乎不像预期的那样运行。

任何帮助,将不胜感激。

编辑: 另一个例子可能有助于

ALTER DATABASE test_db 
set QUOTED_IDENTIFIER OFF 
go 

select "hello" 

结果:


消息207,级别16,状态1,行5 无效列名 '你好' 。

感谢

+1

几乎所有的客户端(例如ADO,ODBC等),将默认设置ANSI_WARNINGS。无论如何,我强烈建议保留它 - 如果你想在这里发生截断,很容易指定一个'SUBSTRING'操作。如果关闭了ansi警告,很多SQL Server的功能都不可用,所以开发需要关闭它们的代码是一个坏习惯。 –

+0

仅供参考http://www.sqlservercentral.com/articles/SET+Options/144571/ – SQL006

+0

感谢达米安 - 如果我能做到这一点,我会喜欢它。不幸的是,这不是我们的选择。我正在将现有服务器迁移到AWS,我需要按原样复制它。我也有一个与quoted_identifiers类似的问题。 – Vandelay

回答

0
--The Issue Occur Because of Length Of Datatype 

    create table #tmp1 
    (test varchar(50) null) 

    insert into #tmp1 
    select 'asfsadfasdsafdafas' 

    select * from #tmp1 
    drop table #tmp1 
--============================== 

When create or alter SQL object like Stored Procedure, User Defined Function in Query Analyzer, it is created with following SQL commands prefixed and suffixed. What are these – QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF? 
SET QUOTED_IDENTIFIER ON 
GO 
SET ANSI_NULLS ON 
GO--SQL PROCEDURE, SQL FUNCTIONS, SQL OBJECTGO 
SET QUOTED_IDENTIFIER OFF 
GO 
SET ANSI_NULLS ON 
GO 

ANSI NULL ON/OFF: 
This option specifies the setting for ANSI NULL comparisons. When this is on, any query that compares a value with a null returns a 0. When off, any query that compares a value with a null returns a null value. 

QUOTED IDENTIFIER ON/OFF: 
This options specifies the setting for usage of double quotation. When this is on, double quotation mark is used as part of the SQL Server identifier (object name). This can be useful in situations in which identifiers are also SQL Server reserved words. 
+0

非常感谢Affaiz - 我将重新修改我的问题 – Vandelay

+0

谢谢 - 我需要能够在数据库级别设置它,以便它在该会话之后持续存在 – Vandelay

+0

右键单击DB >>选项>>已引用标识符已启用ON /关闭 –