//刪除數據表操作
//刪除沒有被關聯的表 drop table if exists 表1,表2,...
//drop命令可以一次性刪除多個表,表之間用逗號隔開。參數if exists可選用於再刪除前判斷刪除的表是否存在,加入該參數後,如果被刪除的表不存在,SQL語句可以順利執行,但會發出警告
>drop table if exist tb_dept2;
//刪除被關聯的表
//再刪除被關聯的表示,可以刪除子表,即有外鍵約束的表,但不可以刪除父表,即在關聯中作爲主鍵的表
//如果要單獨刪除父表,只需將關聯的表的外鍵約束條件取消,然後就可以刪除父表
//創建關聯表
>create table dept2
>(
>id int(11) primary key,
>name varchar(25),
>location varchar(50)
>);
>create table tb_emp
>(
>id int(11) primary key,
>name varchar(25),
>deptid int(11),
>salary float,
>constraint fk_emp_dept2 foreign key(deptid) references tb_dept2(id)
>);
>drop table tb_dept2; //刪除主表tb_dept2失敗,顯示有外鍵關聯
>alter table tb_emp drop foreign key fk_emp_dept2; //刪除外鍵約束條件fk_emp_dept2
>drop table tb_dept2; //刪除父表成功