当前位置:网站首页>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;
边栏推荐
- Comment promouvoir efficacement les produits
- Template engine - FreeMarker first experience
- Making 3D romantic cool photo album [source code attached]
- 智慧家——全家具功能
- 返回值为Object型方法调用equals()
- About EF page turning query database
- Case: drawing Matplotlib dynamic graph
- 在FreeBSD中安装MySQL数据库
- Multiple interface calls, using promise all、Promise. Race and promise any
- 新库上线 | CnOpenData农产品批发价格数据
猜你喜欢

Freertos+stm32l+esp8266+mqtt protocol transmits temperature and humidity data to Tencent cloud IOT platform

C#使用MySql进行操作

Essence and thoughts of 30 lectures on product thinking

JS reverse case: cracking login password

新库上线 | CnOpenDataA股上市公司IPO申报发行文本数据

. Net using access 2010 database

生信周刊第33期

在线小工具分享(不定时更新,当前数量:2)

Error 65:access violation at 0x58024400: no 'read' permission

Computer network knowledge summary (interview)
随机推荐
FIFO code implemented in C language
vite打包构建时 @charset utf-8警告问题处理;
Black box test - decision table method of test cases
Flex & bison start
Online gadget sharing (updated from time to time, current quantity: 2)
Music spectrum display toy -- implementation and application of FFT in stm32
2022年电气试验考试试题模拟考试平台操作
15 `bs对象.节点名称.节点名称.string` 获取嵌套节点内容
Comment promouvoir efficacement les produits
RT-Thread 项目工程搭建和配置--(Env Kconfig)
Handling of @charset UTF-8 warning problems during vite packaging and construction;
黑盒测试 — 测试用例 之 判定表法看这一篇就够了
Simple deepclone
New library launched | cnopendata China new house information data
Return value is object type method call equals()
Android cache usage tool class
[excel knowledge and skills] Excel data type
ASP. Net cache cache usage
数据分析——切片器、数据透视表与数据透视图(职场必备)
新库上线 | CnOpenData农产品批发价格数据