功能:在删除主表时,自动删除副表(外键约束)相应内容
删除包含主键值的行的操作,该值由其它表的现有行中的外键列引用。在级联删除中,还删除其外键值引用删除的主键值的所有行。
如:
create database temp
go
use temp
go
create table UserInfo
(
UserId int identity(1,1) primary key ,
UserName varchar(20),
password varchar(20) not null --密码
)
create table UserDetails
(
id int identity(1,1) primary key,
name varchar(50) not null, --真实姓名
userId int,
foreign key (userId) references UserInfo(UserId) on delete cascade
)
insert UserInfo values ('ly','jeff')
insert UserInfo values('wzq','wzqwzq')
insert UserInfo values('lg','lglg')
insert UserDetails values('李四',1)
insert UserDetails values('王五',2)
insert UserDetails values('刘六',3)
sqlserver 支持级联更新和删除
oracle 只支持级联删除
alter table 表名
add constraint 外键名
foreign key(字段名) references 主表名(字段名)
on delete cascade
语法:
Foreign Key
(column[,...n])
references referenced_table_name[(ref_column[,...n])]
[on delete cascade]
[on update cascade]
注释:
column:列名
referenced_table_name:外键参考的主键表名称
ref_name:外键要参考的表的主键列
on delete:删除级联
on update:更新级联
解决部署K8S集群时flannel无法下载问题
安装kubernetes+docker集群,一篇文章搞定
充值-实体类+查询
充值-controller
多对一的增删改查-list页面,add页面,update页面,tongji页面
多对一的增删改查-dao层
多对一的增删改查-sql语句
多对一的增删改查-controller
多对一的增删改查-service和impl
- 最新文章
-
LeetCode(C++)刷题计划:10-正则表达式匹配
LeetCode(C++)刷题计划:9-回文数
LeetCode(C++)刷题计划:8-字符串转换整数 (atoi)
【第9章 目标代码生成】9.2 假想的计算机模型
[git]实用技能
[git]使用
[git]安装
[英语口语]破冰
java IntelliJ IDEA运行/调试配置
intellij ide写system.out项目名称爆红
- 热门文章
-
C#调用声音函数
【intelli ide】Your idea evaluation has expired[过期]
【Intelli IDE】The environment variable JAVA_HOME (with the value of E:JDK15.0.1in) doesn
python生成各种随机小数,总有一种满足你的需求
Goland配置k8s源码阅读环境
k8s-scheduler源码分析
彻底解决各种浏览器访问不了GitHub问题
spark中的持久化(cache()、persist()、checkpoint())
spark on k8s架构解析
Docker容器