剑谱第二页,小心臭女人-- 图书借阅系统项目数据库建库表语句(组合主键外键设置)
Posted 两掺豆腐脑丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了剑谱第二页,小心臭女人-- 图书借阅系统项目数据库建库表语句(组合主键外键设置)相关的知识,希望对你有一定的参考价值。
剑谱第二页,小心臭女人
/*
切换数据库supperdatabase
*/
use supperdatabase;
SELECT * FROM `supperuser`
模糊查询
注意%匹配的位置
select supperuser.address from supperuser where supperuser.address like "河南%"
select * from supperuser where supperuser.address like "河南%郑%"
/*
**
图书借阅系统项目数据库
**
datbases bookdb 规定字符集为utf8
*/
create database bookdb ENGINE=INNODB DEFAULT CHARACTER=utf8;
/*
进入bookdb下操作
*/
use bookdb;
/*
bookinfo (书籍表)
*/
create table bookinfo(
bookld int primary key default auto_increment COMMENT '书籍编号',
bookName varchar(50) not null COMMENT '书籍名称',
bookWrite varchar(20) not null COMMENT '书籍作者',
bookContent text not null COMMENT '书籍介绍'
)CHARACTER set=utf8;
/*
borrowInfo (借书信息表)
*/
create table borrowInfo(
borrowld int primary key auto_increment COMMENT '借阅编号',
stuName varchar(20) not null COMMENT '学生姓名',
clazz varchar(50) not null COMMENT '班级',
tel varchar(11) not null COMMENT '联系电话',
borrowDate date not null COMMENT '借书日期',
returnDate date COMMENT '还书日期',
status int COMMENT '还书状态 值为0或1 0:已还书 1:未还书',
bookld int COMMENT '外键,所借书籍的编号'
)CHARACTER set=utf8;
/*ENGINE=INNODB DEFAULT CHARACTER=utf8; 设置table字符集为utf8 */
INSERT into bookinfo VALUES(null,"三国演义","罗贯中","东汉末年到西晋初年...");
INSERT into bookinfo VALUES(null,"西游记","吴承恩","孙悟空出世及大闹天宫后...");
INSERT into bookinfo VALUES(null,"水浒传","施耐庵","梁山好汉反抗欺压...");
INSERT into bookinfo VALUES(null,"红楼梦","曹雪芹","贾史王薛四大家族的兴衰...");
INSERT into borrowInfo VALUES(null,"张三","2020级软件一班",18738171861,"2021-02-01","2021-02-09",0,1);
INSERT into borrowInfo VALUES(null,"李四","2020级软件二班",18738171862,"2021-02-03","2021-02-07",0,2);
INSERT into borrowInfo VALUES(null,"王五","2020级软件一班",18738171863,"2021-02-09",null,1,3);
INSERT into borrowInfo VALUES(null,"张三","2020级软件一班",18738171864,"2021-02-10",null,1,4);
/*
查询表查看插入数据
*/
select * from bookinfo;
select * from borrowInfo;
bookinfo表
borrowInfo表
/*
单表设置单个主键 or无外键情况下
*/
use supperdatabase;
create table t3(
nid int not null auto_increment primary key COMMENT '普通主键' ,
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 唯一约束配合自增使用*/
insert into t3 values(DEFAULT,123,12345);
/*
查看t3表数据
*/
select * from t3;
/*
设置符合(2个)主键 外键(2个)
*/
create table t1(
nid int(11) not null auto_increment COMMENT'普通主键' ,
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 唯一约束配合自增使用*/
insert into t1 values(DEFAULT,124,12345);
/*
查看t1表数据
*/
select * from t1;
create table t2(
id int(11) not null auto_increment primary key COMMENT '普通主键',
/*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;
/*
主外键关联时,
添加外键值时 需要根据主键值进行 依次添加
*/
insert into t2 values(DEFAULT,1,12,DEFAULT);
insert into t2 values(DEFAULT,2,123,DEFAULT); /*default 唯一约束配合自增使用*/
insert into t2 values(DEFAULT,3,124,DEFAULT);
/*
查看t2表数据
*/
select *from t2;
/*
查看t1 表结构
*/
desc t1;
/*
查看t2 表结构
*/
desc t2;
以上是关于剑谱第二页,小心臭女人-- 图书借阅系统项目数据库建库表语句(组合主键外键设置)的主要内容,如果未能解决你的问题,请参考以下文章