SQL Reference

Quick Reference

The DROP keyword is used to delete existing columnsconstraintsdatabasesindexestables, and views.

DROP DATABASE

The following deletes a database called “sitename_db”.

DROP DATABASE sitename_db;

DROP TABLE

The following deletes the table Customers.

DROP TABLE Customers;

DROP COLUMN

The following deletes the county secondary_email column from the Customers table.

ALTER TABLE Customers
DROP COLUMN secondary_email;

DROP a UNIQUE CONSTRAINT

The following deletes the unique constraint named uc_customer_names from the Customers table.

MySQL:

ALTER TABLE Customers
DROP INDEX uc_customer_names;

SQL Server:

ALTER TABLE Customers
DROP CONSTRAINT uc_customer_names;

DROP a PRIMARY KEY CONSTRAINT

The following deletes the primary key constraint named pk_customer_names from the Customers table.

MySQL:

ALTER TABLE Customers
DROP PRIMARY KEY;

SQL Server:

ALTER TABLE Customers
DROP CONSTRAINT pk_customer_names;

DROP a FOREIGN KEY CONSTRAINT

The following deletes the foreign key constraint named fk_customer_names from the Customers table.

MySQL:

ALTER TABLE Customers
DROP FOREIGN KEY fk_customer_names;

SQL Server:

ALTER TABLE Customers
DROP CONSTRAINT fk_customer_names;

DROP a CHECK CONSTRAINT

The following deletes the check constraint named chk_age from the Persons table.

MySQL:

ALTER TABLE Persons
DROP CHECK chk_age;

SQL Server:

ALTER TABLE Persons
DROP CONSTRAINT chk_age;

DROP DEFAULT

The following deletes the default country value requirement from the Customers table.

MySQL:

ALTER TABLE Customers
ALTER country DROP DEFAULT;

SQL Server:

ALTER TABLE Customers
ALTER COLUMN country DROP DEFAULT;

DROP INDEX

The following deletes an index named “idx_customer” from the Customers table.

MySQL:

ALTER TABLE Customers
DROP INDEX idx_customer;

SQL Server:

DROP INDEX Customers.idx_customer;

DROP VIEW

The following drops a view called “Canada Customers”.

DROP VIEW [Canadian Customers]';

SQL Notes:

  • Any work being done to modify the structure of a database or delete tables or the the database itself should only be done after making a recent backup

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.