From 5105485f39cf2d6d107abc71d5c86a83ee58426f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=8A=E7=AB=A5?= <10033735+Harshreich@user.noreply.gitee.com> Date: Thu, 15 Sep 2022 15:45:04 +0000 Subject: [PATCH] =?UTF-8?q?=E9=99=88=E6=98=8A=E7=AB=A510?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈昊童 <10033735+Harshreich@user.noreply.gitee.com> --- .../\344\275\234\344\270\232/22.9.15.sql" | 30 +++++++++ ...73\351\224\256\345\244\226\351\224\256.md" | 65 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 "\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.9.15.sql" create mode 100644 "\351\231\210\346\230\212\347\253\245/\347\254\224\350\256\260/22.9.15\347\272\246\346\235\237\344\270\273\351\224\256\345\244\226\351\224\256.md" diff --git "a/\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.9.15.sql" "b/\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.9.15.sql" new file mode 100644 index 0000000..3b6283d --- /dev/null +++ "b/\351\231\210\346\230\212\347\253\245/\344\275\234\344\270\232/22.9.15.sql" @@ -0,0 +1,30 @@ +create database DBTEST; +create table sectioninfo( +sectionID int primary key identity(0,1), +sectionName varchar(10) not null +) +; +create table userinfo( +userNo int primary key identity(0,1), +userName varchar(10) not null unique check(len(userName)>4), +userSex varchar(2) not null check(userSex=''or userSex='Ů'), +userAge int not null check(userAge between 1 and 100), +userAddress varchar(50) default(''), +userSection int references sectioninfo(sectionID) +) +; +create table workinfo( +workId int primary key identity(0,1), +userId int references userinfo(userNo) not null , +workTime datetime not null, +workDescription varchar(40) not null check(workDescription in('ٵ','','','','¼')) +) +; +select * from sectioninfo; +select * from userinfo; +select * from workinfo; +insert into sectioninfo values(''); +insert into userinfo values('3323','','1','','1'); +insert into workinfo values('3','2022-3-3',''); +insert into workinfo values('3','2022-3-3',''); +insert into workinfo values('3','2022-3-3','¼'); diff --git "a/\351\231\210\346\230\212\347\253\245/\347\254\224\350\256\260/22.9.15\347\272\246\346\235\237\344\270\273\351\224\256\345\244\226\351\224\256.md" "b/\351\231\210\346\230\212\347\253\245/\347\254\224\350\256\260/22.9.15\347\272\246\346\235\237\344\270\273\351\224\256\345\244\226\351\224\256.md" new file mode 100644 index 0000000..4773c94 --- /dev/null +++ "b/\351\231\210\346\230\212\347\253\245/\347\254\224\350\256\260/22.9.15\347\272\246\346\235\237\344\270\273\351\224\256\345\244\226\351\224\256.md" @@ -0,0 +1,65 @@ +--关系型数据库:SQL server, Mysql, Oracle +--创建数据库:create database 数据库名 +--database:数据库 + +if exists (select * from sys.databases where name='DBTEST') + drop database DBTEST + + create database DBTEST + + --使用数据库 + use dbtest + + --创建班级表 + create table ClassInfo( + ClassId int primary key identity(1,1), + ClassName varchar(20) + ); + + --插入数据: insert [into] 表名(字段名) values(值) + insert into ClassInfo( ClassName) values('软件1班'); + + insert ClassInfo values('软件2班') + + select * from ClassInfo + + --创建数据表 + create table StuInfo( + stuId int primary key identity(1001,1), --学生ID + --添加一个检查约束,判断用户插入/新增的数据,性别字段是不是男或者女 + --default:默认约束 + --check + stugender varchar(2) not null default('男') check(stugender='男' or stugender='女'), --学生性别 + stuphone char(11) check(len(stuphone)=11) unique, + --创建班级外键 + --ClassID int references ClassInfo(ClassID) + ClassID int + + ); + + + --增加外键 + --修改表结构 表名 add constraint 约束名 foreign key(要引用的字段) references 主键表(字段) + Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key(ClassID) references ClassInfo(ClassID) + + + --新增姓名列 + alter table StuInfo add stuName varchar(20) + + select * from StuInfo; + + --删除表:drop table 表名 + drop table StuInfo + + + --非空 + + --约束,自增(标识列) + + --外键 + --主键:默认唯一列 + --默认 + --唯一: + --check检查: + + --插入数据:insert into \ No newline at end of file -- Gitee