nDefining a foreign key establishes a referential constraint between the foreign key (Child table) and the primary key (parent table)
Create-Foreign key
CREATE TABLE EMPtbl2( (EMPID int NOT NULL, EMPname varchar(255) NOT NULL,company varchar(255),salary varchar(255),City varchar(255), primary key (salary) constraint fk_EMPtbl2 FOREIGN KEY(EMPID1) REFERENCES EMPtbl1(EMPID)
Alter-Foreign key
ALTER TABLE EMPtbl2
ADD CONSTRAINT fk_EMPtbl2 FOREIGN KEY (EMPID, salary)
Drop-Foreign key
ALTER TABLE EMPtbl2
DROP CONSTRAINT fk_EMPtbl2
No comments:
Post a Comment