16.4 CREATE and DROP TABLE

  • CREATE TABLE statement is used for creating relations.

  • Each column is described with three parts:

  1. column name,
  2. data type,
  3. optional constraints.
  • Constraints can be defined within the CREATE TABLE statement, or they can be added to the table after it is created using the ALTER table statement.
  1. PRIMARY KEY
  2. UNIQUE
  3. NULL / NOT NULL
  4. DEFAULT
  5. CHECK
  6. FOREIGN KEY

16.4.1 DROP TABLE

Remove the table definition and all table data and triggers as well.

DROP TABLE IF EXISTS ARTIST ;

If the table has FK,

SET FOREIGN_KEY_CHECKS = 0;
drop table if exists trans;
SET FOREIGN_KEY_CHECKS = 1;

16.4.2 TRUNCATE Table

Remove the data only.

set foreign_key_checks=0;
truncate table customer;
set foreign_key_checks=1;