Logeshwaran Veluchamy
Logeshwaran Veluchamy

Reputation: 181

Removing a primary key column in SQL Server 2008

I have a table named master_employee with a column empid as the primary key, and it has 12 rows in it. This empid has been mapped as a foreign key to another table named dep_child. I want to delete the 12 records in the master_employee table but I was unable to do it.

Upvotes: 0

Views: 68

Answers (2)

Revan
Revan

Reputation: 1144

Add this constraints to your master_employee table

ALTER TABLE "master_employee"

ADD CONSTRAINT "fk_emp11"

FOREIGN KEY ("emp_id")

REFERENCES "dep_child" ("emp_id")

ON DELETE CASCADE;

Upvotes: 0

Incognito
Incognito

Reputation: 3094

You were unable to do the deletes from master_employees, as there is a referential integrity with dep_child. You would need to either disable the constraint or delete the records from dep_child, before being able to delete records from master_employees

Upvotes: 1

Related Questions