Forums » .NET » SQL Server »

How to delete constraint in SQL SERVER ?


Posted Date: 08 Aug 2008      Posted By:: Ramasamy.N Profile photo    Member Level: Gold    Member Rank: 91     Points: 1   Responses: 4



How to delete constraint in SQL SERVER ?



Responses

#278522    Author: Tamilarasan      Member Level: Silver      Member Rank: 0     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 2

Hi,

use the following command..

ALTER TABLE employee
DROP CONSTRAINT pk_employee

H.P.
tamil


 
#278525    Author: Koteswara Rao      Member Level: Gold      Member Rank: 447     Date: 08/Aug/2008   Rating: 2 out of 52 out of 5     Points: 5

CREATE TABLE employee(
EmployeeId INT NOT NULL,
LName VARCHAR(30) NOT NULL,
FName VARCHAR(30) NOT NULL,
Address VARCHAR(100) NOT NULL,
HireDate DATETIME NOT NULL,
Salary MONEY NOT NULL CONSTRAINT check_sale CHECK (salary > 0)
)
====================alter constr=========================
ALTER TABLE employee
ADD CONSTRAINT pk_employee PRIMARY KEY (EmployeeId)
====================delete constr=========================
ALTER TABLE employee
DROP CONSTRAINT pk_employee


 
#286309    Author: Sriram      Member Level: Gold      Member Rank: 0     Date: 25/Aug/2008   Rating: 2 out of 52 out of 5     Points: 0

alter table Products Drop constrain pk_emp




 
#301166    Author: Ravi Kiran Nedunuri      Member Level: Gold      Member Rank: 625     Date: 27/Sep/2008   Rating: 2 out of 52 out of 5     Points: 5

hi you can use the alter command for changing the structure of the table

ex:
create table bank2(cusid int constraint cusid_pk primary key,name varchar(10))

you have created a primary key like this on customer id in bank table

now for droping the constrint use the following command
ALTER TABLE BANK2 DROP CONSTRAINT cusid_pk

or you can use the sqlserver 2005 management studio like this
right on the desired table you can find the edit option click on edit
table appears
in that primary key column appers right click on it and select remove primary key


Regards
N.RaviKiran


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India