[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Non nullable table columns using DB create scripts using SQLCmd More options

Shocky

3/15/2007 12:31:00 PM

Can someone tell me how to create tables with non nullable columns
using SQLCmd(by executing db create scripts)...when I use the scripts
to
create the database all tables that get created have the columns as
nullable

i know that this can be done using create table and mentioning null
or
not null...but I have db creating scripts(scripts for creating
multiple
tables ) which do not have null or not null mentioned for each
column...
by default I want all columns to be non nullable...is there any
parameter that I can set in sql 2005 such that columns of the new
tables that get created are by default non nullable?

Thanks,
Shocky

1 Answer

Tibor Karaszi

3/15/2007 4:30:00 PM

0

It is really really recommended to have NO/NOT NULL in the create table scripts! Having said that:

Check out below two SET commands (that you can have in the beginning of your script file):
SET ANSI_NULL_DFLT_OFF
SET ANSI_NULL_DFLT_ON

Also check out this database option:
ANSI_NULL_DEFAULT

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://sqlblog.com/blogs/tib...


"Shocky" <yusuf.bhiwandiwala@gmail.com> wrote in message
news:1173961859.390784.184130@b75g2000hsg.googlegroups.com...
> Can someone tell me how to create tables with non nullable columns
> using SQLCmd(by executing db create scripts)...when I use the scripts
> to
> create the database all tables that get created have the columns as
> nullable
>
> i know that this can be done using create table and mentioning null
> or
> not null...but I have db creating scripts(scripts for creating
> multiple
> tables ) which do not have null or not null mentioned for each
> column...
> by default I want all columns to be non nullable...is there any
> parameter that I can set in sql 2005 such that columns of the new
> tables that get created are by default non nullable?
>
> Thanks,
> Shocky
>