From c02d303e34f5819b5d8d87f8a7fcf2b74df2a39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 13:56:02 +0000 Subject: [PATCH 01/19] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 6fa2930380fefaec832236fc5cb4f4dfdbaf38d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 13:56:19 +0000 Subject: [PATCH 02/19] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\224\350\256\260/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 31af33c34ef30f2bbc04b5c705ef9d7d6629fb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 13:56:31 +0000 Subject: [PATCH 03/19] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 4916be855f2670a69e7457537096587b63abded6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 13:58:32 +0000 Subject: [PATCH 04/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A/=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\254\224\350\256\260/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\347\254\224\350\256\260/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From 5a33a316208a1f20b3978a7f266e1982b2450b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 13:58:38 +0000 Subject: [PATCH 05/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A/=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From 60e37e8cedc64088838e9b8d7b697e25ba275bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:00:23 +0000 Subject: [PATCH 06/19] =?UTF-8?q?add=2020=E7=8E=8B=E4=B8=96=E8=B4=A2/?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A/2022-9-15?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王世财 <10033750+wang-shicaishicai@user.noreply.gitee.com> --- ...0\200\346\254\241\344\275\234\344\270\232" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" new file mode 100644 index 0000000..45e5046 --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" @@ -0,0 +1,71 @@ +--创建数据库 DBTEST +if exists (select * from sys.databases where name = 'DBTEST') +drop database DBTEST +create database DBTEST; + + +--部门信息表(sectionInfo) +-- 部门编号 sectionID int 标识列 主键 +-- 部门名称 sectionName varchar(10) 不能为空 + +create table sectionInfo( + sectionID int primary key identity(1,1), + sectionName varchar(10) not null +) + +insert sectionInfo values('研发'); +insert sectionInfo values('生产'); +insert sectionInfo values('财务'); +insert sectionInfo values('人事'); +insert sectionInfo values('计划'); + +-- select * from sectionInfo; + +--员工信息表(userInfo) +-- 员工编号 userNo int 标识列 主键 不允许为空 +-- 员工姓名 userName varchar(10) 唯一约束 不允许为空 长度必须大于4 +-- 员工性别 userSex varchar(2) 不允许为空 只能是男或女 +-- 员工年龄 userAge int 不能为空 范围在1-100之间 +-- 员工地址 userAddress varchar(50) 默认值为“湖北” +-- 员工部门 userSection int 外键,引用部门信息表的部门编号 + +--drop table userInfo; + +create table userInfo ( + userNo int identity(1,1) primary key not null, + userName varchar(10) unique not null 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) +); + +insert userInfo (userName,userSex,userAge,userAddress,userSection) +values ('张三123','男','25','福建','1'), + ('李四123','女','30','上海','2'), + ('王五123','女','36','上海','3'), + ('赵六123','女','40','广州','4'), + ('11223','女','27','广州','5'); +--select * from userInfo + +--员工考勤表(workInfo) +-- 考勤编号 workId int 标识列 主键 不能为空 +-- 考勤员工 userId int 外键 引用员工信息表的员工编号 不能为空 +-- 考勤时间 workTime datetime 不能为空 +-- 考勤说明 workDescription varchar(40) 不能为空 内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 + +create table workInfo( + workId int identity(1,1) primary key not null, + userId int references userInfo(userNo) not null, + workTime datetime not null, + workDescription varchar(40) not null check(workDescription = '迟到' or workDescription = '早退' or workDescription = '旷工' or workDescription = '病假' or workDescription = '事假') +) +insert workInfo(userId,workTime,workDescription) +values (1,'2022-1-15 15:15:1','迟到'), + (2,'2022-1-16 15:15:1','早退'), + (3,'2022-1-14 15:15:1','旷工'), + (4,'2022-1-16 15:15:1','病假'), + (5,'2022-1-12 15:15:1','事假'); + + +--select * from workInfo \ No newline at end of file -- Gitee From 10b0361cd055d44273260c0bc6dacaddb6847221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:00:57 +0000 Subject: [PATCH 07/19] =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A220?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王世财 <10033750+wang-shicaishicai@user.noreply.gitee.com> --- .../2022-9-15\347\254\224\350\256\260.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" new file mode 100644 index 0000000..e69de29 -- Gitee From 1c4367471aa5ca7b8b2310dc6ab55337c667bc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:01:17 +0000 Subject: [PATCH 08/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.9.15\347\254\224\350\256\260.md" | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" deleted file mode 100644 index 1d4f017..0000000 --- "a/20\347\216\213\344\270\226\350\264\242/\347\254\224\350\256\260/2022.9.15\347\254\224\350\256\260.md" +++ /dev/null @@ -1,53 +0,0 @@ -# 1.约束 - -- 主键约束 primary key - - ```sql - create table a( - id int primary key identity(1,1) - ) - ``` - - ```sql - alter table 表名 alter column 主键列名 主键类型 not null; - ``` - - - -- 外键约束 foreig key references - -```sql - --修改表结构 表名 add constraint 约束名 foreign key(要引用的字段) references 主键表(字段) - Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key(ClassID) references ClassInfo(ClassID) -``` - -```sql -ClassID int references ClassInfo(ClassID) - ClassID int -``` - -- 默认 default - - ```sql - userAddress varchar(50) default '湖北' - ``` - -- 唯一 unique - - ```sql - userName varchar(10) unique - ``` - -- check - -- 如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 - - 如果对一个表定义 CHECK 约束,那么此约束会基于行中其他列的值在特定的列中对值进行限制。 - - ```sql - userAge int not null check(userAge between 1 and 100) - ``` - - - -- 非空 not null \ No newline at end of file -- Gitee From 9b767069518d8d9381649cb104508524bb088483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:01:23 +0000 Subject: [PATCH 09/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.9.15\344\275\234\344\270\232.sql" | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" diff --git "a/20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" deleted file mode 100644 index e112875..0000000 --- "a/20\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" +++ /dev/null @@ -1,71 +0,0 @@ ---ݿ DBTEST -if exists (select * from sys.databases where name = 'DBTEST') -drop database DBTEST -create database DBTEST; - - ---ϢsectionInfo --- ű sectionID int ʶ --- sectionName varchar(10) Ϊ - -create table sectionInfo( - sectionID int primary key identity(1,1), - sectionName varchar(10) not null -) - -insert sectionInfo values('з'); -insert sectionInfo values(''); -insert sectionInfo values(''); -insert sectionInfo values(''); -insert sectionInfo values('ƻ'); - --- select * from sectionInfo; - ---ԱϢuserInfo --- Ա userNo int ʶ Ϊ --- Ա userName varchar(10) ΨһԼ Ϊ ȱ4 --- ԱԱ userSex varchar(2) Ϊ ֻлŮ --- Ա userAge int Ϊ Χ1-100֮ --- Աַ userAddress varchar(50) ĬֵΪ --- Ա userSection int òϢIJű - ---drop table userInfo; - -create table userInfo ( - userNo int identity(1,1) primary key not null, - userName varchar(10) unique not null 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) -); - -insert userInfo (userName,userSex,userAge,userAddress,userSection) -values ('123','','25','','1'), - ('123','Ů','30','Ϻ','2'), - ('123','Ů','36','Ϻ','3'), - ('123','Ů','40','','4'), - ('11223','Ů','27','','5'); ---select * from userInfo - ---ԱڱworkInfo --- ڱ workId int ʶ Ϊ --- Ա userId int ԱϢԱ Ϊ --- ʱ workTime datetime Ϊ --- ˵ workDescription varchar(40) Ϊ ֻǡٵˡ١¼١еһ - -create table workInfo( - workId int identity(1,1) primary key not null, - userId int references userInfo(userNo) not null, - workTime datetime not null, - workDescription varchar(40) not null check(workDescription = 'ٵ' or workDescription = '' or workDescription = '' or workDescription = '' or workDescription = '¼') -) -insert workInfo(userId,workTime,workDescription) -values (1,'2022-1-15 15:15:1','ٵ'), - (2,'2022-1-16 15:15:1',''), - (3,'2022-1-14 15:15:1',''), - (4,'2022-1-16 15:15:1',''), - (5,'2022-1-12 15:15:1','¼'); - - ---select * from workInfo \ No newline at end of file -- Gitee From bad3f69f44afba93fcfe99c6cb79024691f38b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:01:42 +0000 Subject: [PATCH 10/19] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2020=E7=8E=8B?= =?UTF-8?q?=E4=B8=96=E8=B4=A2/=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=20=E4=B8=BA=2020=E7=8E=8B=E4=B8=96=E8=B4=A2/2022-9-15?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 .../2022-9-15\347\254\224\350\256\260.md" | 0 ...5\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" => "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" (100%) rename "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" => "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" (100%) rename "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" => "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" (100%) diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" similarity index 100% rename from "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" similarity index 100% rename from "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" diff --git "a/20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" similarity index 100% rename from "20\347\216\213\344\270\226\350\264\242/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" rename to "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" -- Gitee From 85bf60d180af1f715583005c5614968eb76092a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:02:59 +0000 Subject: [PATCH 11/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20RE?= =?UTF-8?q?ADME.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 1c4b0e7..0000000 --- a/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# SQL进阶 - -#### 介绍 -11 - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee From cf539f804b9887a093810bc710764d8a72127fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:03:05 +0000 Subject: [PATCH 12/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20RE?= =?UTF-8?q?ADME.en.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 README.en.md diff --git a/README.en.md b/README.en.md deleted file mode 100644 index ac31e94..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# SQL进阶 - -#### Description -11 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee From e32d3943b8380321e696e1c933091c6655178eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:03:12 +0000 Subject: [PATCH 13/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\351\223\276\346\216\245" | 1 - 1 file changed, 1 deletion(-) delete mode 100644 "\351\223\276\346\216\245" diff --git "a/\351\223\276\346\216\245" "b/\351\223\276\346\216\245" deleted file mode 100644 index 9531489..0000000 --- "a/\351\223\276\346\216\245" +++ /dev/null @@ -1 +0,0 @@ -https://gitee.com/organizations/level-21-software-class-4/invite?invite=886e51af49d4c8e870217e863b9617a4db8ea8872269409fe67a7010cd42d36e1326d508fe5ad93be766b0d826817bc9 \ No newline at end of file -- Gitee From d77d103bcb3151f47a547e39cc9006396702fb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:04:22 +0000 Subject: [PATCH 14/19] =?UTF-8?q?=E6=96=B0=E5=BB=BA=202022-9-15=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\200\346\254\241\344\275\234\344\270\232" | 71 ------------------- .../.keep" | 0 2 files changed, 71 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" create mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" deleted file mode 100644 index 45e5046..0000000 --- "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232" +++ /dev/null @@ -1,71 +0,0 @@ ---创建数据库 DBTEST -if exists (select * from sys.databases where name = 'DBTEST') -drop database DBTEST -create database DBTEST; - - ---部门信息表(sectionInfo) --- 部门编号 sectionID int 标识列 主键 --- 部门名称 sectionName varchar(10) 不能为空 - -create table sectionInfo( - sectionID int primary key identity(1,1), - sectionName varchar(10) not null -) - -insert sectionInfo values('研发'); -insert sectionInfo values('生产'); -insert sectionInfo values('财务'); -insert sectionInfo values('人事'); -insert sectionInfo values('计划'); - --- select * from sectionInfo; - ---员工信息表(userInfo) --- 员工编号 userNo int 标识列 主键 不允许为空 --- 员工姓名 userName varchar(10) 唯一约束 不允许为空 长度必须大于4 --- 员工性别 userSex varchar(2) 不允许为空 只能是男或女 --- 员工年龄 userAge int 不能为空 范围在1-100之间 --- 员工地址 userAddress varchar(50) 默认值为“湖北” --- 员工部门 userSection int 外键,引用部门信息表的部门编号 - ---drop table userInfo; - -create table userInfo ( - userNo int identity(1,1) primary key not null, - userName varchar(10) unique not null 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) -); - -insert userInfo (userName,userSex,userAge,userAddress,userSection) -values ('张三123','男','25','福建','1'), - ('李四123','女','30','上海','2'), - ('王五123','女','36','上海','3'), - ('赵六123','女','40','广州','4'), - ('11223','女','27','广州','5'); ---select * from userInfo - ---员工考勤表(workInfo) --- 考勤编号 workId int 标识列 主键 不能为空 --- 考勤员工 userId int 外键 引用员工信息表的员工编号 不能为空 --- 考勤时间 workTime datetime 不能为空 --- 考勤说明 workDescription varchar(40) 不能为空 内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 - -create table workInfo( - workId int identity(1,1) primary key not null, - userId int references userInfo(userNo) not null, - workTime datetime not null, - workDescription varchar(40) not null check(workDescription = '迟到' or workDescription = '早退' or workDescription = '旷工' or workDescription = '病假' or workDescription = '事假') -) -insert workInfo(userId,workTime,workDescription) -values (1,'2022-1-15 15:15:1','迟到'), - (2,'2022-1-16 15:15:1','早退'), - (3,'2022-1-14 15:15:1','旷工'), - (4,'2022-1-16 15:15:1','病假'), - (5,'2022-1-12 15:15:1','事假'); - - ---select * from workInfo \ No newline at end of file diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 7a8f8d6e0c71c9db3a090875cfdb2d729836ca9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:05:54 +0000 Subject: [PATCH 15/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/2022-9-15=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A/2022-9-15=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From edd1e9c75c1bc44174a9423bcabb2695ffae9fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:06:13 +0000 Subject: [PATCH 16/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\344\275\234\344\270\232.sql" | 65 ------------------- ...02\350\257\276\347\254\224\350\256\260.md" | 39 ----------- 2 files changed, 104 deletions(-) delete mode 100644 "\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" delete mode 100644 "\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" diff --git "a/\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" "b/\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" deleted file mode 100644 index 1f50239..0000000 --- "a/\347\216\213\344\270\226\350\264\242/\344\275\234\344\270\232.sql" +++ /dev/null @@ -1,65 +0,0 @@ ---1. 查询出武汉地区所有的员工信息,要求显示部门名称以及员工的详细资料 - -select * from People -inner join Department on People.DepartmentId=Department.DepartmentId -where PeopleAddress='武汉' - ---2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 - -select * from People -inner join Department on People.DepartmentId=Department.DepartmentId -inner join Rank on People.RankId=Rank.RankId -where PeopleAddress ='武汉' - ---3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 - -select DepartmentName,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People -inner join Department on People.DepartmentId=Department.DepartmentId -group by DepartmentName - ---4. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资,平均工资在10000 以下的不参与统计,并且根据平均工资降序排列。 - -select DepartmentName,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People -inner join Department on People.DepartmentId=Department.DepartmentId -group by DepartmentName -having AVG(PeopleSalary)>=10000 -order by AVG(PeopleSalary) desc - ---5. 根据部门名称,然后根据职位名称,分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资 - -select DepartmentName,RankId,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People -inner join Department on People.DepartmentId=Department.DepartmentId -group by RankId,DepartmentName - ---6.查询出巨蟹 6.22--7.22 的员工信息 - -select * from People where MONTH(PeopleBirth)+CONVERT(float,DAY(PeopleBirth))/100 between 6.22 and 7.22 - ---7.查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) - -select *, case - when year(PeopleBirth)%12 =0 - then '猴' - when YEAR(PeopleBirth)%12=1 - then '鸡' - when YEAR(PeopleBirth)%12=2 - then '狗' - when YEAR(PeopleBirth)%12=3 - then '猪' - when YEAR(PeopleBirth)%12=4 - then '鼠' - when YEAR(PeopleBirth)%12=5 - then '牛' - when YEAR(PeopleBirth)%12=6 - then '虎' - when YEAR(PeopleBirth)%12=7 - then '兔' - when YEAR(PeopleBirth)%12=8 - then '龙' - when YEAR(PeopleBirth)%12=9 - then '蛇' - when YEAR(PeopleBirth)%12=10 - then '马' - when YEAR(PeopleBirth)%12=11 - then '羊' - end 生肖 from People \ No newline at end of file diff --git "a/\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" "b/\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" deleted file mode 100644 index ffd706a..0000000 --- "a/\347\216\213\344\270\226\350\264\242/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" +++ /dev/null @@ -1,39 +0,0 @@ -# 1.模糊查询 - -``` -[]:代表匹配范围内 -[^]:代表匹配不在范围内 -select * from Department where DepartmentId like '[1-3]' - -// [1-3] == 1,2,3 - -select * from Department where DepartmentId like '[^1-3]' - -//[^1-3] == 4 -``` - -# 2.CONVERT()与CAST()函数: - -``` -convert(decimal(13,2),12.45454) -cast(12.45454 as decimal(13,2)) -``` - -# 3.时间函数 - -``` -select DATEDIFF(day, '2019-08-20', getDate()); --获取指定时间单位的差值 -SELECT DATEADD(MINUTE,-5,GETDATE()) --加减时间,此处为获取五分钟前的时间,MINUTE 表示分钟,可为 YEAR,MONTH,DAY,HOUR -select DATENAME(month, getDate()); --当前月份 -select DATENAME(WEEKDAY, getDate()); --当前星期几 -select DATEPART(month, getDate()); --当前月份 -select DAY(getDate()); --返回当前日期天数 -select MONTH(getDate()); --返回当前日期月数 -select YEAR(getDate()); --返回当前日期年数 - -SELECT CONVERT(VARCHAR(22),GETDATE(),20) --2020-01-09 14:46:46 -SELECT CONVERT(VARCHAR(24),GETDATE(),21) --2020-01-09 14:46:55.91 -SELECT CONVERT(VARCHAR(22),GETDATE(),23) --2020-01-09 -SELECT CONVERT(VARCHAR(22),GETDATE(),24) --15:04:07 -Select CONVERT(varchar(20),GETDATE(),14) --15:05:49:330 -``` \ No newline at end of file -- Gitee From 7e2fc508cecfe9dc3b634752334b5846e7ae7dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:06:19 +0000 Subject: [PATCH 17/19] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2020?= =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2/2022-9-15=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 .../2022-9-15\347\254\224\350\256\260.md" | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" delete mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/.keep" deleted file mode 100644 index e69de29..0000000 diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022-9-15\347\254\224\350\256\260.md" deleted file mode 100644 index e69de29..0000000 -- Gitee From 57e38787e805f228564fbbdc230584ae4e0dc503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:06:35 +0000 Subject: [PATCH 18/19] add README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王世财 <10033750+wang-shicaishicai@user.noreply.gitee.com> --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..42b200c --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# SQL进阶 + +#### 介绍 +11 + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee From ea1f355ded142beb5fd84e3bf921e17583f275c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=96=E8=B4=A2?= <10033750+wang-shicaishicai@user.noreply.gitee.com> Date: Mon, 19 Sep 2022 14:10:45 +0000 Subject: [PATCH 19/19] =?UTF-8?q?20=E7=8E=8B=E4=B8=96=E8=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王世财 <10033750+wang-shicaishicai@user.noreply.gitee.com> --- .../2022.9.15\344\275\234\344\270\232.sql" | 71 +++++++++++++++++++ .../2022.9.15\347\254\224\350\256\260.md" | 53 ++++++++++++++ .../\344\275\234\344\270\232.sql" | 65 +++++++++++++++++ ...02\350\257\276\347\254\224\350\256\260.md" | 39 ++++++++++ 4 files changed, 228 insertions(+) create mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" create mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" create mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" create mode 100644 "20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..e112875 --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\344\275\234\344\270\232.sql" @@ -0,0 +1,71 @@ +--ݿ DBTEST +if exists (select * from sys.databases where name = 'DBTEST') +drop database DBTEST +create database DBTEST; + + +--ϢsectionInfo +-- ű sectionID int ʶ +-- sectionName varchar(10) Ϊ + +create table sectionInfo( + sectionID int primary key identity(1,1), + sectionName varchar(10) not null +) + +insert sectionInfo values('з'); +insert sectionInfo values(''); +insert sectionInfo values(''); +insert sectionInfo values(''); +insert sectionInfo values('ƻ'); + +-- select * from sectionInfo; + +--ԱϢuserInfo +-- Ա userNo int ʶ Ϊ +-- Ա userName varchar(10) ΨһԼ Ϊ ȱ4 +-- ԱԱ userSex varchar(2) Ϊ ֻлŮ +-- Ա userAge int Ϊ Χ1-100֮ +-- Աַ userAddress varchar(50) ĬֵΪ +-- Ա userSection int òϢIJű + +--drop table userInfo; + +create table userInfo ( + userNo int identity(1,1) primary key not null, + userName varchar(10) unique not null 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) +); + +insert userInfo (userName,userSex,userAge,userAddress,userSection) +values ('123','','25','','1'), + ('123','Ů','30','Ϻ','2'), + ('123','Ů','36','Ϻ','3'), + ('123','Ů','40','','4'), + ('11223','Ů','27','','5'); +--select * from userInfo + +--ԱڱworkInfo +-- ڱ workId int ʶ Ϊ +-- Ա userId int ԱϢԱ Ϊ +-- ʱ workTime datetime Ϊ +-- ˵ workDescription varchar(40) Ϊ ֻǡٵˡ١¼١еһ + +create table workInfo( + workId int identity(1,1) primary key not null, + userId int references userInfo(userNo) not null, + workTime datetime not null, + workDescription varchar(40) not null check(workDescription = 'ٵ' or workDescription = '' or workDescription = '' or workDescription = '' or workDescription = '¼') +) +insert workInfo(userId,workTime,workDescription) +values (1,'2022-1-15 15:15:1','ٵ'), + (2,'2022-1-16 15:15:1',''), + (3,'2022-1-14 15:15:1',''), + (4,'2022-1-16 15:15:1',''), + (5,'2022-1-12 15:15:1','¼'); + + +--select * from workInfo \ No newline at end of file diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" new file mode 100644 index 0000000..1d4f017 --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-15\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/2022.9.15\347\254\224\350\256\260.md" @@ -0,0 +1,53 @@ +# 1.约束 + +- 主键约束 primary key + + ```sql + create table a( + id int primary key identity(1,1) + ) + ``` + + ```sql + alter table 表名 alter column 主键列名 主键类型 not null; + ``` + + + +- 外键约束 foreig key references + +```sql + --修改表结构 表名 add constraint 约束名 foreign key(要引用的字段) references 主键表(字段) + Alter table StuInfo add constraint FK_StuInfo_ClassId foreign key(ClassID) references ClassInfo(ClassID) +``` + +```sql +ClassID int references ClassInfo(ClassID) + ClassID int +``` + +- 默认 default + + ```sql + userAddress varchar(50) default '湖北' + ``` + +- 唯一 unique + + ```sql + userName varchar(10) unique + ``` + +- check + +- 如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 + + 如果对一个表定义 CHECK 约束,那么此约束会基于行中其他列的值在特定的列中对值进行限制。 + + ```sql + userAge int not null check(userAge between 1 and 100) + ``` + + + +- 非空 not null \ No newline at end of file diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..1f50239 --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -0,0 +1,65 @@ +--1. 查询出武汉地区所有的员工信息,要求显示部门名称以及员工的详细资料 + +select * from People +inner join Department on People.DepartmentId=Department.DepartmentId +where PeopleAddress='武汉' + +--2. 查询出武汉地区所有的员工信息,要求显示部门名称,职级名称以及员工的详细资料 + +select * from People +inner join Department on People.DepartmentId=Department.DepartmentId +inner join Rank on People.RankId=Rank.RankId +where PeopleAddress ='武汉' + +--3. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资。 + +select DepartmentName,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People +inner join Department on People.DepartmentId=Department.DepartmentId +group by DepartmentName + +--4. 根据部门分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资,平均工资在10000 以下的不参与统计,并且根据平均工资降序排列。 + +select DepartmentName,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People +inner join Department on People.DepartmentId=Department.DepartmentId +group by DepartmentName +having AVG(PeopleSalary)>=10000 +order by AVG(PeopleSalary) desc + +--5. 根据部门名称,然后根据职位名称,分组统计员工人数,员工工资总和,平均工资,最高工资和最低工资 + +select DepartmentName,RankId,COUNT(People.DepartmentId)人数,SUM(PeopleSalary)工资总和,AVG(PeopleSalary)平均工资,MAX(PeopleSalary)最高工资,MIN(PeopleSalary)最低工资 from People +inner join Department on People.DepartmentId=Department.DepartmentId +group by RankId,DepartmentName + +--6.查询出巨蟹 6.22--7.22 的员工信息 + +select * from People where MONTH(PeopleBirth)+CONVERT(float,DAY(PeopleBirth))/100 between 6.22 and 7.22 + +--7.查询所有员工信息,添加一列显示属相(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪) + +select *, case + when year(PeopleBirth)%12 =0 + then '猴' + when YEAR(PeopleBirth)%12=1 + then '鸡' + when YEAR(PeopleBirth)%12=2 + then '狗' + when YEAR(PeopleBirth)%12=3 + then '猪' + when YEAR(PeopleBirth)%12=4 + then '鼠' + when YEAR(PeopleBirth)%12=5 + then '牛' + when YEAR(PeopleBirth)%12=6 + then '虎' + when YEAR(PeopleBirth)%12=7 + then '兔' + when YEAR(PeopleBirth)%12=8 + then '龙' + when YEAR(PeopleBirth)%12=9 + then '蛇' + when YEAR(PeopleBirth)%12=10 + then '马' + when YEAR(PeopleBirth)%12=11 + then '羊' + end 生肖 from People \ No newline at end of file diff --git "a/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" new file mode 100644 index 0000000..ffd706a --- /dev/null +++ "b/20\347\216\213\344\270\226\350\264\242/2022-9-16\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\347\254\254\344\272\214\350\212\202\350\257\276\347\254\224\350\256\260.md" @@ -0,0 +1,39 @@ +# 1.模糊查询 + +``` +[]:代表匹配范围内 +[^]:代表匹配不在范围内 +select * from Department where DepartmentId like '[1-3]' + +// [1-3] == 1,2,3 + +select * from Department where DepartmentId like '[^1-3]' + +//[^1-3] == 4 +``` + +# 2.CONVERT()与CAST()函数: + +``` +convert(decimal(13,2),12.45454) +cast(12.45454 as decimal(13,2)) +``` + +# 3.时间函数 + +``` +select DATEDIFF(day, '2019-08-20', getDate()); --获取指定时间单位的差值 +SELECT DATEADD(MINUTE,-5,GETDATE()) --加减时间,此处为获取五分钟前的时间,MINUTE 表示分钟,可为 YEAR,MONTH,DAY,HOUR +select DATENAME(month, getDate()); --当前月份 +select DATENAME(WEEKDAY, getDate()); --当前星期几 +select DATEPART(month, getDate()); --当前月份 +select DAY(getDate()); --返回当前日期天数 +select MONTH(getDate()); --返回当前日期月数 +select YEAR(getDate()); --返回当前日期年数 + +SELECT CONVERT(VARCHAR(22),GETDATE(),20) --2020-01-09 14:46:46 +SELECT CONVERT(VARCHAR(24),GETDATE(),21) --2020-01-09 14:46:55.91 +SELECT CONVERT(VARCHAR(22),GETDATE(),23) --2020-01-09 +SELECT CONVERT(VARCHAR(22),GETDATE(),24) --15:04:07 +Select CONVERT(varchar(20),GETDATE(),14) --15:05:49:330 +``` \ No newline at end of file -- Gitee