1. 程式人生 > >mysql經典語句(外來鍵開關)

mysql經典語句(外來鍵開關)

-- 查詢所有表的語句
select table_name 
from information_schema.tables 

where table_schema='當前資料庫名'

--外來鍵
drop table if EXISTS `userinfo`;
create table `userinfo`(
`id` int(10) primary key auto_increment,
`username` varchar(50) not null,
`userpwd` varchar(50) not null,
`pic` varchar(64) not null
)engine=innodb default CHARSET=utf8;
drop table if exists `attendance1`;
create table `attendance1`(
`id` int(10) primary key auto_increment,
`creatime1` datetime not null,
`state` int(5) default 1 not null,
`name1` varchar(20) not null ,
`remark` varchar(50),
`userid` int(8) not null,
key `fk_attendance1_userid`(`userid`),
constraint `fk_attendance1_userid` foreign key(`userid`) references `userinfo`(`id`)
)engine=innodb default CHARSET=utf8;


--外來鍵開關
-- 外來鍵關 
SET FOREIGN_KEY_CHECKS=0;
-- 外來鍵開 
SET FOREIGN_KEY_CHECKS=1;