| | |
How to add not null column in SQL Server 2005
![]() |
•
•
Join Date: Sep 2006
Posts: 116
Reputation:
Solved Threads: 0
I have to add a not null column in a table.
I am using
It gives me error
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'xyz' cannot be added to non-empty table 'abc' because it does not satisfy these conditions.
can anybody have any idea, what's wrong with my SP?
?
I am using
MS SQL Syntax (Toggle Plain Text)
IF NOT EXISTS(SELECT * FROM information_schema.COLUMNS WHERE column_name = 'xyz' AND table_name = 'abc') BEGIN ALTER TABLE abc WITH NOCHECK ADD xyz MONEY NOT NULL END
It gives me error
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'xyz' cannot be added to non-empty table 'abc' because it does not satisfy these conditions.
can anybody have any idea, what's wrong with my SP?
?
Last edited by peter_budo; Apr 7th, 2008 at 5:25 am. Reason: Keep It Organized - please use [code] tags
You can't, simply when you add a column all rows before this adding have this column = null, so you can remove all rows and add a non-nullable column.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- Open In New Window Php (PHP)
Other Threads in the MS SQL Forum
- Previous Thread: retrieval of unique data
- Next Thread: Info needed regarding SQL server 2005
Views: 15726 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last 2005 access age auto autogrowth business comparing comparison. count csharp cursor data database dataset dateadd datediff datepart dates day" dbsize deadlock difference exploit fill function getdate hack helpwithhomework install join joins limit live maximum money ms mssql mssql2005 multiple multithreading mysql news null number partitioning password position query reporting result rules security select server services sets single source sql sql-injection sqlserver subtype sum supertype tables tsql unicode-sql update view weekday






