Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
insanepaul
Posting Yak Master
178 Posts |
Posted - 2009-03-17 : 05:27:48
|
| Is it possible to write a script to change a table's column from nullable to not null as we have a load of the same databases on several servers and I don't really want to manually do this.If it's possible can you tell me what the script is.Many thanks |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2009-03-17 : 05:30:37
|
Yes you can provided either the table is empty or the column contains non-null values.Following is the command for this:alter table <table-name>alter column foo int not null Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
sagitariusmzi
Posting Yak Master
113 Posts |
Posted - 2009-03-17 : 05:45:34
|
| alter table tablename alter column columnname datatype not nullgo |
 |
|
|
insanepaul
Posting Yak Master
178 Posts |
Posted - 2009-03-17 : 05:47:17
|
quote: Originally posted by harsh_athalye Yes you can provided either the table is empty or the column contains non-null values.Following is the command for this:alter table <table-name>alter column foo int not null
Thats great, thanks it saved me a lot of work |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-17 : 10:36:29
|
| This will work if table does not have any data. if it has existing data with null values in column you need to specify a default value alsoalter table <table-name>alter column foo int not null default -1 |
 |
|
|
|
|
|