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
Abraham Kuriak...
(79)
Deepika Harida...
(64)
shekhar
(60)
Last 7 Days
UmaShankar
(1211)
ANIL PANDEY
(659)
Deepika Harida...
(484)
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
SQL Date Time important functions
How to find the session ID of the current user process in SQL Server
How to get the first day of the week, last day of the week and last day of the month using T-SQL dat
How to Copy only Unique Records from one Table to Another Table
Customized sorting order
dotNet Slackers
BizTalk Adaptors
Web Design
it outsourcing
Contact Us
Privacy Policy
Terms Of Use