Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi friends
i have add new field in table like

ALTER TABLE TestTable
ADD NewCol bit default 0

and my question is how to set default value 1

thanks
Posted
Comments
jaideepsinh 5-Jul-13 7:03am    
Accept as answer and vote is solve you problem.

Try this...:)



SQL
ALTER TABLE Employee 
ALTER COLUMN CityBorn SET DEFAULT 'SANDNES'
 
Share this answer
 
Comments
[no name] 4-Jul-13 7:57am    
its not working get error like
Incorrect syntax near the keyword 'SET'
Nirav Prabtani 4-Jul-13 8:08am    
ALTER TABLE Protocols
ADD ProtocolTypeID int NOT NULL DEFAULT(1)
GO
Hi....

Check the below code

SQL
-- Syntax
ALTER TABLE TABLE_NAME ADD COLUMN_NAME DATATYPE NULL|NOT NULL CONSTRAINT CONSTRAINT_NAME DEFAULT DEFAULT_VALUE
-- Example 
ALTER TABLE Employee_Details ADD isacitve INT NULL CONSTRAINT DF_TABLE_COL_ISACTIVE DEFAULT '0'

Regards,
GVPrabu
 
Share this answer
 
try this...:)

SQL
ALTER TABLE Protocols
ADD ProtocolTypeID int NOT NULL DEFAULT(1)
GO
 
Share this answer
 
SQL
Alter table TestTable
Add isWork bit not null Default(1)

Go
this one set your old value to 1 and if you insert null value it automatically take 1.

Accept as answer and vote if help to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900