Back to list Standard SQL How to Delete a Foreign Key Constraint in SQL Database: SQL MySQL PostgreSQL Oracle SQL Server Operators:DROP CONSTRAINT, DROP FOREIGN KEY, ALTER TABLE Problem: You want to drop a foreign key from a table in a database. Example: We want to remove the foreign key named fk_student_city_id from the table student. Solution 1 (new table): ALTER TABLE student DROP CONSTRAINT fk_student_city_id; Discussion: To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint. In our example, the name of this constraint is fk_student_city_id. If the constraint for the foreign key was generated by the database, you can find this name in the database. However, each database server has a different way to name constraints. In SQL Server, you can check it by selecting data from sys.key_constraints in the given database. In PostgreSQL, you select the conname column from the pg_constraint table. Oracle stores this data in the user_constraints table, and MySQL allows you to get names from CONSTRAINT_NAME column in information_schema.TABLE_CONSTRAINTS. Recommended courses: The Basics of Creating Tables Data Types in SQL SQL Constraints Recommended articles: What is a Primary Key in SQL? How to Create a Table in SQL Referential Constraints and Foreign Keys in MySQL Understanding Numerical Data Types in SQL See also: How to Create a Table with a Foreign Key in SQL How to Create a Primary Key in SQL How to Remove a Primary Key in SQL Tags: SQL MySQL PostgreSQL Oracle SQL Server Subscribe to our newsletter Join our weekly newsletter to be notified about the latest posts.