I am trying this query to drop a foreign key ALTER TABLE dbo.[User] DROP FOREIGN KEY FK_User_UserTypeID
.
But I am getting this
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'FOREIGN'.
I am trying this query to drop a foreign key ALTER TABLE dbo.[User] DROP FOREIGN KEY FK_User_UserTypeID
.
But I am getting this
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'FOREIGN'.
SQL FOREIGN KEY on CREATE TABLE : -
CREATE TABLE Orders (
OrderID int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int FOREIGN KEY REFERENCES Persons(PersonID)
);
SQL FOREIGN KEY on ALTER TABLE :-
ALTER TABLE Orders
ADD CONSTRAINT FK_PersonOrder
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);
DROP a FOREIGN KEY Constraint :-
ALTER TABLE Orders
DROP CONSTRAINT FK_PersonOrder;
NOTE Should not have any dependency on foreign key while dropping key constraints, otherwise you will not be able to drop the constraint.