mysql 添加外键
create table class(
cid tinyint unsigned primary key auto_increment,
caption varchar(15) not null
)engine=innodb;
create table student(
sid smallint unsigned primary key auto_increment,
sname varchar(15) not null,
gender enum('male','female') default 'male',
class_id tinyint unsigned,
constraint fk_name foreign key(class_id)
references class(cid)
on delete cascade
on update cascade
)engine=innodb;
create table teacher(
tid tinyint unsigned primary key auto_increment,
tname varchar(15) not null
)engine=innodb;
create table course(
cid smallint unsigned primary key auto_increment,
cname varchar(15) not null,
teacher_id tinyint unsigned,
constraint fk_teacher_id foreign key(teacher_id)
references teacher(tid)
on delete cascade
on update cascade
)engine=innodb;
create table score(
sid int unsigned primary key auto_increment,
number tinyint unique not null,
student_id smallint unsigned,
course_id smallint unsigned,
constraint fk_student foreign key(student_id)
references student(sid),
constraint fk_course foreign key(course_id)
references course(cid)
on delete cascade
on update cascade
)engine=innodb;
mysql 添加外键的更多相关文章
- mysql添加外键无法成功的原因
最近很忙,碰到很多问题都忘了发上来做个记录,现在又忘了,FUCK,现在碰到一个问题, 就是mysql添加外键总是无法成功,我什么都试了,就是没注意signed和unsigned,FUCK,因为我用my ...
- MySQL中MyISAM与InnoDB区别及选择,mysql添加外键
InnoDB:支持事务处理等不加锁读取支持外键支持行锁不支持FULLTEXT类型的索引不保存表的具体行数,扫描表来计算有多少行DELETE 表时,是一行一行的删除InnoDB 把数据和索引存放在表空间 ...
- MySQL添加外键的方法
为book表添加外键: <1>明确指定外键的名称: 语法:alter table 表名 add constraint 外键的名称 foreign key(你的外键字段名) REFERENC ...
- mysql 添加外键详解
为已经添加好的数据表添加外键: 语法:alter table 表名 add constraint FK_ID foreign key(你的外键字段名) REFERENCES 外表表名(对应的表的主键字 ...
- MySQL添加外键报错 - referencing column 'xx' and referenced column 'xx' in foreign key constraint 'xx' are incompatible
MySQL给两个表添加外键时,报错 翻译意思是:外键约束“xx”中的引用列“xx”和引用列“xx”不兼容 说明两个表关联的列数据类型不一致,比如:varchar 与 int,或者 int无符号 与 i ...
- Mysql添加外键约束
简单说一下使用外键的好处 1.完整性约束 比如:用户表中有字段 用户编号(id) , 名称(username)设备表中有字段 设备编号(id) , 设备名称(devicename) 设备属于的用户编号 ...
- mysql添加外键的4种方式
今天开始复习,在过后的几天里开始在博客上记录一下平时疏忽的知识点,温故而知新 屁话不多--直接上货 创建主表: 班级 CREATE TABLE class(cid INT PRIMARY KEY AU ...
- MYSQL添加外键关联
SELECT * from stu st,course co,score sc where st.sid = sc.sid and sc.cid = co.cid 如果我们要给 sid 做一个约束,即 ...
- mysql添加外键语句
sql语句格式: · 添加外键约束:alter table 从表 add constraint 外键(形如:FK_从表_主表) foreign key (从表外键字段) references 主表(主 ...
- mysql添加外键约束变为索引
今天有位自己填上一坑:mysql储存引擎 原因就是数据库表引擎为:MyISAM,建立主外键关系需要是InnoDB: 解决方案:alter table table_name1 engine=inno ...
随机推荐
- LeetCode OJ 24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- JAVA字符串格式化-String.format()的使用【转】
原文地址:https://blog.csdn.net/lonely_fireworks/article/details/7962171 常规类型的格式化 String类的format()方法用于创建格 ...
- hmac md5
import hmac //内置 def simaplemd5(str): m2 = hashlib.md5() m2.update(str) res=m2.hexdigest() return re ...
- easyUi onLoadSuccess:、onChange这些事件不能嵌套使用!!!!
easyUi onLoadSuccess:.onChange这些事件不能嵌套使用!!!!
- MySQL 数据 导入到 SQL Service
1.下载安装ODBC驱动程序 地址:http://dev.mysql.com/downloads/connector/odbc/ 注意:系统的版本问题( 我的是64位的win7系统,但是SQL Ser ...
- pip 离线安装
pip download ansible -d . --trusted-host mirrors.aliyun.com pip install ansible-2.7.5.tar.gz --user ...
- go io包
https://studygolang.com/articles/9424 https://blog.csdn.net/trochiluses/article/details/44338407
- 05_ssm基础(四)之Spring与持久层的整合
30.31.spring对jdbc的支持jdbcTemplate 使用Spring的JDBC准备: 1):拷贝jar: mysql-connector-java-5.1.11.jar:M ...
- SQL Server 2008中SQL增强之一:Values新用途 001
连接集合 select '1' as id,'wang' as name union select '2' as id,'admin' as name 现在可以这么写了 select id,name ...
- JVisual 相关help参数
The launcher has determined that the parent process has a console and will reuse it for its own cons ...