Tutorials
Resources
Forum
Communities
Interview
Jobs
Projects
Offshore Development
Silverlight Tutorials
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Revenue Sharing
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Deepika Harida...
(114)
Abraham Kuriak...
(101)
shekhar
(81)
Last 7 Days
UmaShankar
(1211)
ANIL PANDEY
(659)
Deepika Harida...
(534)
more...
New Feature:
Community Sites
:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
How to drop Constraints in SQL Server
Posted Date: 04 May 2008 Resource Type:
Code Snippets
Category:
SQL
Posted By:
@@@ Hyderabadi Biryani @@@
Member Level:
Diamond
Rating:
Points
: 15
The following code sample shows how to drop Constraints in SQL Server
declare @name nvarchar(32),
@sql nvarchar(1000)
-- find constraint name
select @name = O.name
from sysobjects AS O
left join sysobjects AS T
on O.parent_obj = T.id
where isnull(objectproperty(O.id,'IsMSShipped'),1) = 0
and O.name not like '%dtproper%'
and O.name not like 'dt[_]%'
and T.name = 'MyTable'
and O.name like 'DF__MyTable__MyColu%'
-- delete if found
if not @name is null
begin
select @sql = 'ALTER TABLE [MyTable] DROP CONSTRAINT [' + @name + ']'
execute sp_executesql @sql
end
-- do your ALTER TABLE here
-- replace the constraint
select @sql = 'ALTER TABLE [MyTable] ADD CONSTRAINT [' + @name + '] DEFAULT (0) FOR [MyColumn]'
execute sp_executesql @sql
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Import data directly from excel
Previous Resource:
How to check whether a Column exists in table if not then add it to the table
Return to Discussion Resource Index
Post New Resource
Category:
SQL
Post resources and
earn money
!
Related Resources
Store & Retrieve images from SQL
How to get date part from a datetime column
How to get code Execution Time
Save an image file to database using a stored proc
Cascading deletes using trigger
dotNet Slackers
BizTalk Adaptors
Web Design
budget conference call
Contact Us
Privacy Policy
Terms Of Use