diff --git "a/\344\275\234\344\270\232/\344\275\234\344\270\232.sql" "b/\344\275\234\344\270\232/\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8266a0bdbf79d7e57574c6a57b0c10512b74a36a --- /dev/null +++ "b/\344\275\234\344\270\232/\344\275\234\344\270\232.sql" @@ -0,0 +1,98 @@ +create database DBTEST; +use DBTEST; + + +--部门信息表 +create table sectionInfo( + +--部门编号 + sectionID int primary key identity (1001,1), + +--部门名称 + sectionName varchar(10) not null + +); + + +insert into sectionInfo (sectionName) values ('销售部'); +insert into sectionInfo (sectionName) values('财务部'); +insert into sectionInfo (sectionName) values('前端开发部'); +insert into sectionInfo (sectionName) values('后端开发部'); +insert into sectionInfo (sectionName) values('测试部'); + + +select * from sectionInfo; + + +--员工信息表 +create table userInfo( + +--员工编号 + userNo int primary key identity (2001,1) not null, + + --员工姓名 + userName varchar(10) not null unique check(len(UserName)>4), + +--员工性别 + userSex varchar(2) not null check(userSex='男'or userSex='女'), + + --员工年龄 + userAge int not null check(1<=userAge or userAge <=100), + +--员工地址 + userAddress varchar(50) default('湖北'), + +--员工部门,外键引用部门信息表的部门编号 + userSection int +); + + +select * from userInfo; + + +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values('张三三三三','男',22,'湖北',1001); +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values('李四四四四','男',28,'湖北',1002); +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values('王五五五五','男',35,'湖北',1003); +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values('黄丽丽丽丽','女',22,'湖北',1004); +insert into userInfo(userName,userSex,userAge,userAddress,userSection) values('马蓉蓉蓉蓉','女',56,'湖北',1005); + + + +--员工考勤表 +create table workinfo( + +--考勤编号 +workID int primary key not null identity(3001,1), + +--考勤员工,外键,引用的是员工信息表的员工编号 +userId int not null, + +--考勤时间 +workTime datetime not null, + +--考勤说明,内容只能是“迟到”,“早退”,“旷工”,“病假”,“事假”中的一种 +workDescription varchar(40) not null , + +check(workDescription='迟到'or workDescription='早退' or workDescription='旷工' or workDescription='病假' or workDescription='事假') + +); + + +insert into workinfo(userId,workTime,workDescription) values (2007,2021-2-11,'迟到'); +insert into workinfo(userId,workTime,workDescription) values (2008,2022-3-13,'早退'); +insert into workinfo(userId,workTime,workDescription) values (2009,2021-1-19,'旷工'); +insert into workinfo(userId,workTime,workDescription) values (2010,2022-7-1,'病假'); +insert into workinfo(userId,workTime,workDescription) values (2011,2022-6-24,'事假'); + +select * from workinfo; + + +--外键 + +--员工信息表连部门表 + Alter table userInfo add constraint aaa foreign key (userSection) references sectionInfo(sectionID); + +--员工考勤表连员工信息表 +Alter table workinfo add constraint bbb foreign key (userId) references userInfo(userNo); + + diff --git "a/\344\275\234\344\270\232/\347\254\224\350\256\260.txt" "b/\344\275\234\344\270\232/\347\254\224\350\256\260.txt" new file mode 100644 index 0000000000000000000000000000000000000000..8036792692f7850f9128372924aa239a67940889 --- /dev/null +++ "b/\344\275\234\344\270\232/\347\254\224\350\256\260.txt" @@ -0,0 +1,19 @@ +create database锛堝缓鏁版嵁搴擄級 DBTEST(鏁版嵁搴撳悕绉); +use DBTEST;锛堜娇鐢ㄦ暟鎹簱锛 + + +create table(寤鸿〃) userInfo(琛ㄥ悕绉)锛堣繖閲屾槸澧炲姞鍒 +璇彞1 +璇彞2 +..... + +锛 +primary key 鏄富閿 +鍒楀悕+绫诲瀷+primary key 鏄富閿+identity (1001,1)锛堣繖鏄嚜澧 鍏朵腑1001鏄叾瀹炵偣锛1鏄嚜澧為噺锛 闈炵┖灏辩洿鎺ヨ窡 not null 娉細杩欎簺璇彞鐨勯『搴忔槸涓嶅畾鐨 +check妫鏌 渚嬪 +鍒楀悕+绫诲瀷 check锛坙en鏄暱搴︼紙鍒楀悕=4锛夛級杩欏氨鏄浐瀹氳繖鍒楃殑闀垮害涓4 +鍏朵腑鍋囧 闇瑕佺殑闇姹傛槸澶т簬1灏忎簬100鏄棤娉昪heck锛1<鍒楀悕<100锛夌殑浜嗭紝寰楃敤or锛堟垨鑰咃級鏉ュ紕check锛1<鍒楀悕 or 鍒楀悕>100锛 + + +娣诲姞澶栭敭鐨勬柟娉曟湁涓ょ鍏朵腑 Alter table 鐨勬剰鎬濇槸淇敼琛ㄧ粨鏋 鎵浠ユ槸鍦ㄥ悗闈㈣繘琛屾坊鍔犵殑 add灏辨槸娣诲姞鐨勬剰鎬 constraint涔熷氨鏄浐瀹氱粨鏋 鍚庨潰璺熷閿悕绉帮紝foreign key涔熸槸鍥哄畾 锛堬級 +Alter table userInfo add constraint aaa foreign key (userSection) references sectionInfo(sectionID); \ No newline at end of file