IFNOTEXISTS(SELECT * FROM information_schema.COLUMNSWHERE column_name = 'xyz'
AND table_name = 'abc')
BEGIN
ALTERTABLE abc WITH NOCHECK ADD xyz MONEY NOTNULL
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 6:25 am. Reason: Keep It Organized - please use [code] tags
U cant add a not null column using ALTER command.Because it allows
to add only null columns.If u want to add datas into that null column you need to use UPDATE command for adding data into that table
Like,
UPDATE TABLE table_name SET null_column-name='value' WHERE column_name='value
EX
UPDATE TABLE employee SET add1='SARA' WHERE sno=1
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.