当前位置:网站首页>MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
2022-06-26 01:25:00 【Mixed with bean curd and】
Sword manual page 2 , Watch out for smelly women
/*
Switch database supperdatabase
*/
use supperdatabase;
SELECT * FROM `supperuser`

Fuzzy query
Be careful % The matching position
select supperuser.address from supperuser where supperuser.address like " Henan %"

select * from supperuser where supperuser.address like " Henan % zheng %"

/*
**
Book borrowing system project database
**
datbases bookdb The specified character set is utf8
*/
create database bookdb ENGINE=INNODB DEFAULT CHARACTER=utf8;
/*
Get into bookdb Lower operation
*/
use bookdb;
/*
bookinfo ( Book list )
*/
create table bookinfo(
bookld int primary key default auto_increment COMMENT ' Book number ',
bookName varchar(50) not null COMMENT ' Book name ',
bookWrite varchar(20) not null COMMENT ' Book author ',
bookContent text not null COMMENT ' Book Introduction '
)CHARACTER set=utf8;
/*
borrowInfo ( Loan information sheet )
*/
create table borrowInfo(
borrowld int primary key auto_increment COMMENT ' Loan No ',
stuName varchar(20) not null COMMENT ' The student's name ',
clazz varchar(50) not null COMMENT ' class ',
tel varchar(11) not null COMMENT ' contact number ',
borrowDate date not null COMMENT ' Borrowing date ',
returnDate date COMMENT ' Return date ',
status int COMMENT ' Return status The value is 0 or 1 0: Returned books 1: Outstanding books ',
bookld int COMMENT ' Foreign keys , The number of the book borrowed '
)CHARACTER set=utf8;
/*ENGINE=INNODB DEFAULT CHARACTER=utf8; Set up table The character set is utf8 */
INSERT into bookinfo VALUES(null," The romance of The Three Kingdoms "," Luo Guanzhong "," From the late Eastern Han Dynasty to the early Western Jin Dynasty ...");
INSERT into bookinfo VALUES(null," Journey to the west "," Wu chengen "," After the birth of Monkey King and the havoc in heaven ...");
INSERT into bookinfo VALUES(null," Water margin "," Shi Naian "," Liangshan hero resists oppression ...");
INSERT into bookinfo VALUES(null," A dream of red mansions "," Cao xueqin "," The rise and fall of the four great families of Jia Shi Wang Xue ...");
INSERT into borrowInfo VALUES(null," Zhang San ","2020 First class software ",18738171861,"2021-02-01","2021-02-09",0,1);
INSERT into borrowInfo VALUES(null," Li Si ","2020 Class 2 of level 2 software ",18738171862,"2021-02-03","2021-02-07",0,2);
INSERT into borrowInfo VALUES(null," Wang Wu ","2020 First class software ",18738171863,"2021-02-09",null,1,3);
INSERT into borrowInfo VALUES(null," Zhang San ","2020 First class software ",18738171864,"2021-02-10",null,1,4);
/*
Query the table to view the inserted data
*/
select * from bookinfo;
select * from borrowInfo;
bookinfo surface 
borrowInfo surface 
/*
Set a single primary key for a single table or Without foreign keys
*/
use supperdatabase;
create table t3(
nid int not null auto_increment primary key COMMENT ' Common primary key ' ,
pid int(11) not null ,
num int(11) null
)CHARACTER set=utf8;
insert into t3 values(1,12,123);
insert into t3 values(DEFAULT,122,1234); /*default The unique constraint is used with autoincrement */
insert into t3 values(DEFAULT,123,12345);
/*
see t3 Table data
*/
select * from t3;

/*
The settings match (2 individual ) Primary key Foreign keys (2 individual )
*/
create table t1(
nid int(11) not null auto_increment COMMENT' Common primary key ' ,
pid int(11) default null,
num int(11) default null,
primary key (nid,pid)
)CHARACTER set=utf8;
insert into t1 values(DEFAULT,12,123);
insert into t1 values(DEFAULT,123,1234); /*default The unique constraint is used with autoincrement */
insert into t1 values(DEFAULT,124,12345);
/*
see t1 Table data
*/
select * from t1;

create table t2(
id int(11) not null auto_increment primary key COMMENT ' Common primary key ',
/*pid int(11) default null,*/
id1 int,
id2 int ,
num int(11) default null,
CONSTRAINT fk_t2_t1 foreign key (id1, id2) references t1(nid, pid)
)CHARACTER set=utf8;
/*
When the primary foreign key is associated ,
When adding foreign key values It needs to be done according to the primary key value Add... In turn
*/
insert into t2 values(DEFAULT,1,12,DEFAULT);
insert into t2 values(DEFAULT,2,123,DEFAULT); /*default The unique constraint is used with autoincrement */
insert into t2 values(DEFAULT,3,124,DEFAULT);
/*
see t2 Table data
*/
select *from t2;
/*
see t1 Table structure
*/
desc t1;

/*
see t2 Table structure
*/
desc t2;
边栏推荐
- 计算机网络知识总结(面试)
- Web information collection, naked runners on the Internet
- JS reverse case: cracking login password
- 远程增量同步神器rsync
- Flex & bison start
- Laravel basic course routing and MVC - controller
- 返回值为Object型方法调用equals()
- Is it safe to open a securities account online
- Dgus new upgrade: fully support digital video playback function
- Installation and startup of redis
猜你喜欢

Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.

超详细SSM框架实现增删改查功能项目整体流程

DGUS新升级:全面支持数字视频播放功能

Shengxin weekly issue 33

STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme

Nacos registry

New library launched | cnopendata China new house information data

Optimized three-dimensional space positioning method and its fast implementation in C language

“热帖”统计

数字电路——加法器
随机推荐
单选框互斥且可同时取消选中
Multiple interface calls, using promise all、Promise. Race and promise any
Online gadget sharing (updated from time to time, current quantity: 2)
Solution to MySQL error code 2003
Etcd database source code analysis cluster communication initialization
Remote incremental synchronization artifact Rsync
原生DOM与虚拟DOM
Simple deepclone
Tools - API document generation tool
走 迷 宫
在FreeBSD中安装MySQL数据库
Sqlserver is case sensitive
Embedded C first learning notes
leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
Flex & Bison 开始
Is it safe for flush software to buy stocks for trading? How to open an account to buy shares
[understanding of opportunity -30]: Guiguzi - internal "chapter - empathy, stand on the other side's position and narrow the psychological distance with the other side
填鸭数据即时收集解决方案资源
数组中的第K个最大元素
mysql错误代码2003的解决办法