2017-08-17 60 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 /關閉 –