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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 creating a column with not null constraint

Author  Topic 

sudha12345
Starting Member

47 Posts

Posted - 2009-06-08 : 05:51:14
i had a existing table with 5 columns. i has to add a column
sap_id wih type numeric(28,0) with not null constraint (not to allow null values).

how can we do this

Sudhakar

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-06-08 : 05:54:19
In a existing table (with data) you can't include a not not column.

Instead of this you do like this.

1.Include a column with null (i.e allow null)
2.update value into the new column.
3.Now set the not null constrain.




Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-06-08 : 07:12:13
add column with default value for already existing table.

Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-06-08 : 08:07:20
ALTER TABLE tablename ADD sap_id NUMERIC(28,0) NOT NULL default(0)

- Lumbago
Go to Top of Page
   

- Advertisement -