数据库外键,数据库
外键
创建:
方式1:在创建表时使用foreign key(字段名) references 表名(主键);
方式2:通过修改表结构add foreign key(字段名) references 表名(主键);
删除:
alter table 表名 drop foreign key 外键名;
如果查看外键名:show create table 表名;
外键的约束:
B表中的某一个字段是A表的主键字段。
A表为主表,B表为从表:
主表被从表约束。
1、A表本身不能随意 被删除
2、A表中的记录的变动,不能随意删除或更新数据,言外之意有一定的约束
置空约束
当主表的记录删除时,那么从表中的记录中的外键字段调用为null
语法:
on delete set null
级联约束
当主表的记录更新时,那么从表中的记录中的外键字段同步更新。
从表被主表约束
1、从表的数据:从表中的外键字段的值,必须是,主表中的主键字段中的某一个值。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software