mysql经典语句(外键开关)
2018-01-17 10:04
232 查看
-- 查找所有表的语句
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;
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;
相关文章推荐
- 【MySQL】经典数据库SQL语句编写练习题——SQL语句扫盲
- MYSQL常用DDL,DML语句及外键创建
- mysql中表设置了外键关联,可以语句强制更新
- Mysql操作语句-外键管理
- 经典MYSQL语句
- mysql中的alter语句的经典用法
- MySQL学习笔记--DQL、DML、DDL、TCL语句,约束(主键、外键)
- MySQL常用经典语句
- MySQL数据操作的经典语句
- Mysql主键 外键笔记:一起来简单谈谈sql语句
- mysql的经典查询语句
- MYSQL经典语句大全——基础篇
- mysql 经典语句
- MySQL 创建主键,外键和复合主键的语句
- mysql建立不上外键,sql语句一运行完就会生成一条索引,但是外键却建不上
- mysql 之 sql 语句 之 多表外键
- MySql经典语句
- MySQL常用经典语句
- 经典MySQL语句收藏(高手必备)
- MySQL常用经典语句