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 |
|
henrikop
Constraint Violating Yak Guru
280 Posts |
Posted - 2005-07-22 : 10:25:46
|
| I read some articles about ALTER TABLE to alter columns in a table and the 'funny' names enterprise manager gives to constraints. I learned to give constraints names so I can easy drop the constraint.However. I cannot find the method to alter a column to be not nullable. If I use profiler I see that the whole table is re-created.My question is: How can I (afterwards) make a column not NULLABLE with t-sql in a manner so I can control the constraint name?Thx!Henri~~~~The envious praises me unknowingly |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2005-07-22 : 13:26:19
|
| The NULL-ability of a column is not really a named constraint. It's an attribute of the column itself. So therefore you need to ALTER TABLE ... ALTER COLUMN... to change the NULL or NOT NULL setting.I suppose that if you really, really, really wanted a named constraint, you could create some sort of CHECK CONSTRAINT to do it, but why bother?---------------------------EmeraldCityDomains.com |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-07-22 : 13:26:40
|
From BOL:Column NullabilityA column can be defined to either allow or disallow null values. By default, a column permits null values.An existing column can be changed to disallow null values only if no existing null values exist in the column and there is no existing index created on the column. To disallow null values in an existing column that contains null values: Add a new column with a DEFAULT definition that inserts a valid value in place of NULL.Copy the data in the old (existing) column to the new column.Delete the old column. An existing column that does not allow null values can be changed to allow null values unless a PRIMARY KEY constraint is defined on the column. *need more coffee*SELECT * FROM Users WHERE CLUE > 0(0 row(s) affected) |
 |
|
|
|
|
|