Main Page | Report this Page
Computers Forum Index  »  Computer - Databases - MS SQL Server  »  add columun using default value...
Page 1 of 1    

add columun using default value...

Author Message
Deep...
Posted: Thu Oct 29, 2009 1:41 pm
Guest
Dear sir
I want to add one column in table using alter command and want to
set default value.
How it is possible please help me
Thanks in advance.

Regards
Vinod
 
Plamen Ratchev...
Posted: Thu Oct 29, 2009 6:07 pm
Guest
You have to use ALTER TABLE, here is example:

CREATE TABLE Foo (
keycol INT NOT NULL PRIMARY KEY);

ALTER TABLE Foo
ADD datacol VARCHAR(10) NOT NULL
CONSTRAINT df_datacol DEFAULT 'N/A';

INSERT INTO Foo (keycol) VALUES(1);

SELECT keycol, datacol
FROM Foo;

DROP TABLE Foo;

More details on ALTER TABLE:
http://msdn.microsoft.com/en-us/library/ms190273.aspx?ppud=4

--
Plamen Ratchev
http://www.SQLStudio.com
 
 
Page 1 of 1    
All times are GMT
The time now is Tue Nov 24, 2009 5:57 am