Learning Curve…

How to check if constraints exist in a column in sql server?

Posted on: February 27, 2012

You can check if constraints exist in a column in sql server  and if its not there you can alter table to add a constraint using below query :-

IF NOT EXISTS (SELECT  *  FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ConstraintsName]’))
    ALTER TABLE [dbo].[TableName] ADD  CONSTRAINT [ConstraintsName]  DEFAULT (newid()) FOR [ContactID]
GO

Happy Coding !!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Author

Learning days (Calendar)

February 2012
M T W T F S S
« Jan   Mar »
 12345
6789101112
13141516171819
20212223242526
272829  

Knowledge Bank (Archives)

I am on Twitter

Blog Stats

  • 507,655 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 43 other followers

%d bloggers like this: