CREATE DATABASE example;
USE example;
CREATE TABLE department(
d_id INT(4) NOT NULL UNIQUE PRIMARY KEY,
d_name VARCHAR(20) NOT NULL UNIQUE,
function VARCHAR(50),
address VARCHAR(50)
);
DESC department;
CREATE TABLE worker(
id INT(4) NOT NULL UNIQUE PRIMARY KEY AUTO_INCREMENT,
num INT(10) NOT NULL UNIQUE,
d_id INT(4),
name VARCHAR(20) NOT NULL,
sex VARCHAR(4) NOT NULL,
birthday DATE,
address VARCHAR(50),
CONSTRAINT worker_fk FOREIGN KEY(d_id) REFERENCES department(d_id)
);
SHOW CREATE TABLE worker \G
ALTER TABLE worker DROP FOREIGN KEY worker_fk;
SHOW CREATE TABLE worker \G
DROP TABLE department;