Add a constraint to a column in an existing table.

Hi,
How  do I add a new column with  the constraint
DEFAULT (suser_sname())
to an existing table.

We can Call the new column FlagOpen

Cheers
RIASAsked:
Who is Participating?
 
Máté FarkasConnect With a Mentor Database Developer and AdministratorCommented:
Sorry:
ALTER TABLE Test1
	ADD [User] VARCHAR(128) NOT NULL CONSTRAINT DF_Test1_User DEFAULT (suser_name()) 

Open in new window

0
 
Máté FarkasDatabase Developer and AdministratorCommented:
ALTER TABLE dbo.YourTable
	ADD [NewColumnName] float NOT NULL CONSTRAINT DF_YourTableName_NewColumnName DEFAULT (0) 

Open in new window

0
 
RIASAuthor Commented:
Thanks will try and brb
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
RIASAuthor Commented:
Thanks, how can I add constraint DEFAULT (suser_sname())
0
 
RIASAuthor Commented:
Trying this
ALTER TABLE Test1
      ADD [User] VARCHAR(128) NOT NULL CONSTRAINT DF_Test1_User DEFAULT (suser_name())
0
 
RIASAuthor Commented:
Thanks worked like charm!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.