set ANSI_NULL_DFLT_OFF (Transact-sql)

Yeni sütun nullability varsayılan geçersiz kılmak için oturum davranışını değiştirir olduğunda ANSI null defaultveritabanı için bir seçenek true. Değerini ayarlama hakkında daha fazla bilgi için ANSI null defaultbakın alter veritabanı (Transact-sql).

Konu bağlantısı simgesi Transact-SQL Sözdizim Kuralları

Sözdizimi

SET ANSI_NULL_DFLT_OFF { ON | OFF }

Açıklamalar

Sütun nullability create table ve alter table deyimleri belirtilen zaman bu ayar yalnızca yeni sütun nullability etkiler. Varsayılan olarak, create table ve alter table deyimleri kullanarak oluşturulan yeni sütunlar değildir set ANSI_NULL_DFLT_OFF on olduğunda sütun nullability durumunu açıkça belirtilmemişse, null. set ANSI_NULL_DFLT_OFF açık bir null kullanarak oluşturulan sütunlar etkilemez veya not null.

set ANSI_NULL_DFLT_OFF ve set ANSI_NULL_DFLT_ON on aynı anda ayarlanamıyor. Bir seçenek on olarak ayarlanmışsa, diğer seçenek off ayarlanır. Bu nedenle, ANSI_NULL_DFLT_OFF ya da set ANSI_NULL_DFLT_ON on ayarlayabilir veya her ikisi de off ayarlayabilirsiniz. Her iki seçenek on olarak ayarlanmışsa, bu ayar (set ANSI_NULL_DFLT_OFF ya da set ANSI_NULL_DFLT_ON) etkili olur. off, iki seçenek ayarlanırsa SQL Serverdeğerini kullanır is_ansi_null_default_onsütununda sys.databases Katalog görünümü.

Bir daha güvenilir çalışması için Transact-SQLveritabanları farklı nullability ayarları ile kullanılan komut dosyalarını, bunun create table ve alter table deyimleri null olmayan veya her zaman null belirtmek daha iyi.

set ANSI_NULL_DFLT_OFF ayarı ayarlanır yürütme veya zaman değil ayrıştırma saati ve çalıştırın.

İzinler

Üyelik publicrolü.

Örnekler

Aşağıdaki örnek etkilerini gösterir.Set SET ANSI_NULL_DFLT_OFFiki ayarları ile ANSI null defaultveritabanı seçeneği.

USE AdventureWorks2012;
GO

-- Set the 'ANSI null default' database option to true by executing 
-- ALTER DATABASE.
GO
ALTER DATABASE AdventureWorks2012 SET ANSI_NULL_DEFAULT ON;
GO
-- Create table t1.
CREATE TABLE t1 (a TINYINT);
GO
-- NULL INSERT should succeed.
INSERT INTO t1 (a) VALUES (NULL);
GO

-- SET ANSI_NULL_DFLT_OFF to ON and create table t2.
SET ANSI_NULL_DFLT_OFF ON;
GO
CREATE TABLE t2 (a TINYINT);
GO 
-- NULL INSERT should fail.
INSERT INTO t2 (a) VALUES (NULL);
GO

-- SET ANSI_NULL_DFLT_OFF to OFF and create table t3.
SET ANSI_NULL_DFLT_OFF OFF;
GO
CREATE TABLE t3 (a TINYINT) ;
GO 
-- NULL INSERT should succeed.
INSERT INTO t3 (a) VALUES (NULL);
GO

-- This illustrates the effect of having both the database
-- option and SET option disabled.
-- Set the 'ANSI null default' database option to false.
ALTER DATABASE AdventureWorks2012 SET ANSI_NULL_DEFAULT OFF;
GO
-- Create table t4.
CREATE TABLE t4 (a tinyint) ;
GO 
-- NULL INSERT should fail.
INSERT INTO t4 (a) VALUES (null);
GO

-- SET ANSI_NULL_DFLT_OFF to ON and create table t5.
SET ANSI_NULL_DFLT_OFF ON;
GO
CREATE TABLE t5 (a tinyint);
GO 
-- NULL insert should fail.
INSERT INTO t5 (a) VALUES (null);
GO

-- SET ANSI_NULL_DFLT_OFF to OFF and create table t6.
SET ANSI_NULL_DFLT_OFF OFF;
GO
CREATE TABLE t6 (a tinyint); 
GO 
-- NULL insert should fail.
INSERT INTO t6 (a) VALUES (null);
GO

-- Drop tables t1 through t6.
DROP TABLE t1, t2, t3, t4, t5, t6;

USE AdventureWorks2012;
GO

-- Set the 'ANSI null default' database option to true by executing 
-- ALTER DATABASE.
GO
ALTER DATABASE AdventureWorks2012 SET ANSI_NULL_DEFAULT ON;
GO
-- Create table t1.
CREATE TABLE t1 (a TINYINT);
GO
-- NULL INSERT should succeed.
INSERT INTO t1 (a) VALUES (NULL);
GO

-- SET ANSI_NULL_DFLT_OFF to ON and create table t2.
SET ANSI_NULL_DFLT_OFF ON;
GO
CREATE TABLE t2 (a TINYINT);
GO 
-- NULL INSERT should fail.
INSERT INTO t2 (a) VALUES (NULL);
GO

-- SET ANSI_NULL_DFLT_OFF to OFF and create table t3.
SET ANSI_NULL_DFLT_OFF OFF;
GO
CREATE TABLE t3 (a TINYINT) ;
GO 
-- NULL INSERT should succeed.
INSERT INTO t3 (a) VALUES (NULL);
GO

-- This illustrates the effect of having both the database
-- option and SET option disabled.
-- Set the 'ANSI null default' database option to false.
ALTER DATABASE AdventureWorks2012 SET ANSI_NULL_DEFAULT OFF;
GO
-- Create table t4.
CREATE TABLE t4 (a tinyint) ;
GO 
-- NULL INSERT should fail.
INSERT INTO t4 (a) VALUES (null);
GO

-- SET ANSI_NULL_DFLT_OFF to ON and create table t5.
SET ANSI_NULL_DFLT_OFF ON;
GO
CREATE TABLE t5 (a tinyint);
GO 
-- NULL insert should fail.
INSERT INTO t5 (a) VALUES (null);
GO

-- SET ANSI_NULL_DFLT_OFF to OFF and create table t6.
SET ANSI_NULL_DFLT_OFF OFF;
GO
CREATE TABLE t6 (a tinyint); 
GO 
-- NULL insert should fail.
INSERT INTO t6 (a) VALUES (null);
GO

-- Drop tables t1 through t6.
DROP TABLE t1, t2, t3, t4, t5, t6;

Ayrıca bkz.

Başvuru

ALTER TABLE (Transact-SQL)

Tablo (Transact-sql) oluştur

Deyimiyle (Transact-sql) bırak

set ANSI_NULL_DFLT_ON (Transact-sql)