Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to drop a Check constraint

Author  Topic 

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-25 : 02:57:07
please help me in dropping the check constraint in a table which I have created already.

for example :
create table random (eno int, ename varchar(10), check(eno>10));

A table named random was created using the above statement. Now if I want to drop the check constraint, please give the solution.

tvspsekhar

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-25 : 03:02:52
quote:
Originally posted by tvspsekhar

please help me in dropping the check constraint in a table which I have created already.

for example :
create table random (eno int, ename varchar(10), check(eno>10));

A table named random was created using the above statement. Now if I want to drop the check constraint, please give the solution.

tvspsekhar



ALTER TABLE random
DROP CONSTRAINT constraintname
Go to Top of Page

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-25 : 03:06:48
Thank U Mr haroon2k9.
But While creating the table I have not given any name to the constraint.

tvspsekhar
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-25 : 04:54:30
Find the name of the constraint.b4 execute change the table name and then do below and drop it then
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 = 'tbalename'

print @name
Go to Top of Page

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-25 : 05:54:35
Thank U verymuch Mr haroon2k9

tvspsekhar
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-25 : 05:58:40
quote:
Originally posted by tvspsekhar

Thank U verymuch Mr haroon2k9

tvspsekhar



Welcome.
Go to Top of Page
   

- Advertisement -