diff --git "a/23\346\236\227\344\270\226\346\266\233/.keep" "b/23\346\236\227\344\270\226\346\266\233/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.15\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.15\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..0360b300855cbc9da3aaeb200b197d5ed1cc5e13 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.15\344\275\234\344\270\232.sql" @@ -0,0 +1,26 @@ + + create database DBTEST + use DBTEST + create table sectionInfo( + sectionID int primary key not null identity(1,1), + sectionName varchar(20) not null + + ); + +create table userInfo( + userNo int primary key not null identity(1,1), + userName varchar(20) not null check(len(userName)>4)unique, + userSex varchar(2) not null default('男') check( userSex='男' or userSex='女'), + userAge int not null check(len(userAge)>1 and len(userAge)<100), + userAddress varchar(50) default('湖南'), + userSection int references sectionInfo(sectionID), + +); + +create table workInfo( + workId int primary key not null identity(1,1), + userId int not null references userInfo(userNo), + workTime datetime not null, + workDescription varchar(40) not null check(workDescription='迟到' or workDescription='早退' or workDescription='旷工' or workDescription='病假'), + +); diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.16\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.16\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..8bff4ae2b25c54ee745fa0b36c8943ed5bc17d43 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.16\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/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.19\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.19\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..44beb7a2bd5dcfe0464505081780952579a49670 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.19\344\275\234\344\270\232.sql" @@ -0,0 +1,36 @@ +--1. 关羽的银行卡号为"6225547858741263",查询出余额比关羽多的银行卡信息,显示卡号,身份证,姓名,余额。 + +select * from BankCard +inner join AccountInfo on AccountInfo.AccountId=BankCard.AccountId +where CardMoney>(select CardMoney from BankCard where CardNo=6225547858741263) + +--2. 从所有账户信息中查询出余额最高的交易明细(存钱取钱信息)。 + +select * from CardExchange where MoneyInBank-MoneyOutBank=(select MAX(MoneyInBank-MoneyOutBank) from CardExchange) + +--3. 查询有取款记录的银行卡及账户信息,显示卡号,身份证,姓名,余额。 + +select * from BankCard +inner join AccountInfo on BankCard.AccountId=AccountInfo.AccountId +where BankCard.CardNo=(select CardNoOut from CardTransfer) + +--4. 查询出没有存款记录的银行卡及账户信息,显示卡号,身份证,姓名,余额。 + +select * from BankCard +inner join AccountInfo on BankCard.AccountId=AccountInfo.AccountId +where CardNo not in (select cardNo from CardExchange) + +--5. 关羽的银行卡号为"6225547858741263",查询当天是否有收到转账。 + +select CardNoIn from CardTransfer where CardNoIn=6225547858741263 + +--6. 查询出交易次数(存款取款操作)最多的银行卡账户信息,显示:卡号,身份证,姓名,余额,交易次数。 + +select * ,COUNT(BankCard.CardNo),RANK()over(order by COUNT(BankCard.CardNo))排名 from BankCard +inner join AccountInfo on AccountInfo.AccountId=BankCard.AccountId +inner join (select CardNo from CardExchange group by CardNo)huhu on huhu.CardNo=BankCard.CardNo + +--7. 查询出没有转账交易记录的银行卡账户信息,显示卡号,身份证,姓名,余额。 + +select * from BankCard inner join AccountInfo on AccountInfo.AccountId=BankCard.AccountId +where CardNo not in (select CardNoIn from CardTransfer) and CardNo not in (select CardNoOut from CardTransfer) \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.21\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.21\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..a68177ec81d7077c4d561aba55cf9a6b4cfefe54 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.21\344\275\234\344\270\232.sql" @@ -0,0 +1,50 @@ +--13. 按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩 +select huhu.SId,平均成绩,sc1.CId,sc1.score, sc2.CId,sc2.score, sc3.CId,sc3.score from( +select SC.SId,AVG(SC.score)平均成绩 from SC +group by SC.SId +) huhu +left join SC sc1 on sc1.SId=huhu.SId and sc1.CId=1 +left join SC sc2 on sc2.SId=huhu.SId and sc2.CId=2 +left join SC sc3 on sc3.SId=huhu.SId and sc3.CId=3 +order by 平均成绩 desc + + +--14. 查询各科成绩最高分、最低分和平均分: + +--以如下形式显示:课程 ID,课程 name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率 + +--及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90 + +--要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列 + +select SC.CId,Cname,MAX(score)最高分,MIN(score)最低分,AVG(score)平均成绩 from SC +inner join Course on Course.CId=SC.CId group by SC.CId,Cname order by COUNT(SC.CId) desc,CId + +--15. 按各科成绩进行排序,并显示排名, Score 重复时保留名次空缺 +select s.sid,sname,t1.语文排名,t2.数学排名,t3.英语排名 from student s +left join +( +select sid,rank() over(order by score desc) 语文排名 from sc where cid = '01' +) t1 on t1.sid = s.sid +left join +( +select sid,rank() over(order by score desc) 数学排名 from sc where cid = '02' +) t2 on t2.sid = s.sid +left join +( +select sid,rank() over(order by score desc) 英语排名 from sc where cid = '03' +) t3 on t3.sid = s.sid +--15.1 按各科成绩进行排序,并显示排名, Score 重复时合并名次 + +select * from Student s +left join(select SId,DENSE_RANK() over(order by score desc)排名1 from SC where CId=1) sc1 on sc1.SId=s.SId +left join (select SId,DENSE_RANK()over(order by score desc)排名2 from SC where CId=2) sc2 on sc2.SId=s.SId +left join (select SId,DENSE_RANK()over(order by score desc)排名3 from SC where CId=3) sc3 on sc3.SId=s.SId + +--16. 查询学生的总成绩,并进行排名,总分重复时保留名次空缺 + +select SId,sum(score)总分,RANK() over(order by sum(score) desc)排名 from SC group by SId + +--16.1 查询学生的总成绩,并进行排名,总分重复时不保留名次空缺 + +select SId,sum(score)总分,DENSE_RANK() over(order by sum(score) desc) 排名 from SC group by SId \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.22\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.22\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..49147aeb73e46d03c3ee2cfca89300eb9195a7c4 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.22\344\275\234\344\270\232.sql" @@ -0,0 +1,90 @@ +--1. 为赵云此人进行开户开卡操作,赵云身份证:420107199904054233 +use BankTest + +select * from AccountInfo +select * from BankCard +declare @name varchar(50) = '赵云',@accCode varchar(50) = '420107199904054233' +insert into AccountInfo(AccountCode,AccountPhone,RealName,OpenTime) +values(@accCode,'18815974623',@name,getdate()) + + + +--2. 需要求出张飞的银行卡卡号和余额,张飞身份证:420107199602034138 (1.使用连接查询,2.使用变量) +declare @cardno varchar(50),@money money +select @cardno = CardNo,@money = CardMoney from AccountInfo a +join BankCard b on a.AccountId = b.AccountId +where AccountCode = '420107199602034138' +print '银行卡卡号为'+ @cardno + ',余额为' + cast(@money as varchar(50)) + + +--#### 逻辑控制 + +--##### 条件分支if-else + +--​ 3.某用户银行卡号为“6225547854125656”,该用户执行取钱操作,取钱5000元, +--余额充足则进行取钱操作,并提示"取钱成功",否则提示“余额不足”。 +declare @money int +select @money = (select CardMoney from BankCard where CardNo = '6225547854125656') +if(@money > 5000) +begin + select @money = (select (CardMoney-5000) from BankCard where CardNo = '6225547854125656') + print '取钱成功,余额为' + cast(@money as varchar(50)) +end +else +begin + print '余额不足' +end + + + +--##### 条件分支:case-when + +--​ 4.查询银行卡信息,将银行卡状态1,2,3,4分别转换为汉字“正常,挂失,冻结,注销”, +--并且根据银行卡余额显示银行卡等级 30万以下为“普通用户”,30万及以上为"VIP用户", +----显示列分别为卡号,身份证,姓名,余额,用户等级,银行卡状态。 +select +CardNo 卡号, +(select AccountCode from AccountInfo a where a.AccountId = b.AccountId) 身份证, +(select RealName from AccountInfo a where a.AccountId = b.AccountId) 姓名, +CardMoney 余额, +case + when CardState = 1 then '正常' + when CardState = 1 then '挂失' + when CardState = 1 then '冻结' + else '注销' + end as 银行卡状态, +case + when CardMoney > 300000 then 'VIP用户' + else '普通用户' + end as 用户等级 +from BankCard b + + +--##### **while** + +--​ 5.循环打印1-10。 +declare @i int =1 +while(@i <= 10) +begin + print @i + set @i += 1 +end + +--​ 6.打印99乘法表 +--1*123456789 当第二段数字=9时,第一段数字加1, 1*1=1 +--, @cheng varchar, @deng varchar +--set @cheng = '*' +--set @deng = '=' +declare @num1 int = 1, @num2 int = 1 +while(@num1 <= 9) +begin + print cast(@num1 as varchar(50)) + '*' + cast(@num2 as varchar(50)) + '=' + cast((@num1 * @num2) as varchar(50)) + set @num2 += 1 + + if(@num2 = 10) + begin + set @num2 = 1 + set @num1 += 1 + end + +end \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.23\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.23\344\275\234\344\270\232.sql" new file mode 100644 index 0000000000000000000000000000000000000000..32ab13b5522ba8bee235fcd82595f58e6991447f --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.09.23\344\275\234\344\270\232.sql" @@ -0,0 +1,14 @@ +----1.创建tb_student(name)索引 填充因子设为50 +select * from tb_student +create nonclustered index huhu on tb_student(name) with (fillfactor=50) + +--2.创建tb_record(borrow_time,return_time) 使用索引查询没还书的同学并且让没还书的同学将图书归还 +create index huahua on tb_record(borrow_time,return_time) +select * from tb_record where return_time is null + +----3.增加新列id() 创建聚集索引tb_book(id) + +alter table tb_book add id int +go +drop index PK__tb_book__C16E36F9679CD14B on tb_book +create clustered index lala on tb_book(id) \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.15\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.15\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..87c21ec77913798e1daa0bdd86fe979c95a3fbd6 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.15\347\254\224\350\256\260.md" @@ -0,0 +1,2 @@ +今天学了代码建库 +真是充实有意义的一天 \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.16\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.16\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..81d70b5c6db2d28e8182c53c4bbe0f9321f0dcb1 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.16\347\254\224\350\256\260.md" @@ -0,0 +1,2 @@ +更加熟练的掌握了select +又是充实而有意义的一节课 \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.19\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.19\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..a90c0061d4991612bf65bc5f82b8fdc51b5c1888 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.19\347\254\224\350\256\260.md" @@ -0,0 +1,2 @@ +更深入学习了sql sever +很充实的一节课 \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.21\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.21\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..7f03e990b2008d13209cfcd75ab1a5ca0c861eb6 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.21\347\254\224\350\256\260.md" @@ -0,0 +1,2 @@ +对sql的学习更深入了 +非常充实的一天 \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.22\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.22\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..95a038e9b71bef6c3e16ad40e448da51b35f6535 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.22\347\254\224\350\256\260.md" @@ -0,0 +1,60 @@ +1.变量 +1.1局部变量 +局部变量必须以标记@作为前缀 ,如@age 局部变量的使用是先声明,再赋值 局部变量只在定义它的局部范围内有效 + +声明一个局部变量:declare @变量名 数据类型 + +--例: + declare @id int --声明一个名为id的整型变量 + declare @name varchar(50) --声明一个可变长度为50的存放姓名的字符串变量 +赋值: + +set @变量名 = 值 + +select @变量名 = 值 + +--例: + select @id = 1001 + set @name = '周飘' +set与select赋值的区别: + +set赋值给变量指定的值,select一般用于表中查询出的数据赋值给变量,如果查询结果有多条,取最后一条赋值给变量 + +1.2全局变量 +全局变量必须以标记@@作为前缀,如@@version 全局变量由系统定义和维护,我们只能读取,不能修改全局变量的值 全局变量在整个SQL环境下都可以被访问或调用 + +--@@ERROR:返回执行的上一个语句的错误号 +--@@IDENTITY:返回最后插入的标识值 +--@@MAX_CONNECTIONS:返回允许同时进行的最大用户连接数 +--@@ROWCOUNT:返回受上一语句影响的行数 +--@@SERVERNAME:返回运行 SQL Server 的本地服务器的名称 +--@@SERVICENAME:返回 SQL Server 正在其下运行的注册表项的名称 +--@@TRANCOUNT:返回当前连接的活动事务数 +--@@LOCK_TIMEOUT:返回当前会话的当前锁定超时设置(毫秒) +2.逻辑控制语句 +2.1 if else +if(条件) + begin + 语句1 + 语句2 + end + +else + begin + 语句1 + 语句2 + end +2.2循环控制语句 +while(条件) + begin + 语句1 + 语句2 + end +2.3逻辑控制语句 switch case +3.批处理语句 +go语句特点: + +等待go语句前的代码执行完成后,再执行go后面的代码。 +批处理语句的结束标志。 +4.总结 +变量的使用。要先用DECLARE 关键字声明,然后用SET或SELECT赋值。局部变量前必须有 “@” 作前缀,全局变量必须有 “@@” 作前缀。 变量的输出可以用:PRINT或SELECT语句。 逻辑控制语句提供了条件操作所需的顺序和逻辑。 了解T-SQL编写工具。 批处理可以提高语句执行的效率,使用“GO”作为结束标志。 \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.23\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.23\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..3ac42ac2193ab39f64674c24f5b0955ea9acbada --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.09.23\347\254\224\350\256\260.md" @@ -0,0 +1,54 @@ +1.索引 +1.1作用 +提高查询速度 + +保证数据记录的唯一性 + +查询优化靠索引起作用 + +提高order by, group by 执行速度 + +1.2分类 +1.2.1聚集索引(clustered): +根据数据行的键值在表或视图中的排序存储这些数据行,每个表只有一个聚集索引。聚集索引是一种对磁盘上实际数据重新组织以按指定的一列或多列值排序(类似字典中的拼音索引)(物理存储顺序)。 + +​ 聚集索引的意思可以理解为顺序排列,比如一个主键自增的表即为聚集索引,即id为1的存在于第一条,id为2的存在于第二条...假使数据库中是使用数组来存放的这张表中的数据,那么如果我需要查找第100条,那么直接第一条数据的地址加上100即为第一百条的地址,一次就能查询出来。 + +1.2.2非聚集索引 (nonclusterted): +具有独立于数据行的结构,包含非聚集索引键值,且每个键值项都有指向包含该键值的数据行的指针。(类似字典中的偏旁部首索引)(逻辑存储顺序)。 + +非聚集索引可以简单理解为有序目录,是一种以空间换取时间的方法。举个例子,在一个user表中,有一个id_num,即身份号,此不为主键id,那么这些数据在存储的时候都是无序的,比如 + +id为1的id_num为100,id为2的id_num为97,id为3的id_num为98,id为4的id_num为99,id为5的id_num为96。。。id为67的id_num为56。。。 + +那么如果我要查找id_num为56的人,那么只能一条一条的遍历,n条就需要查询n次,时间复杂度为O(n),这是非常耗费性能的。 + +所以,现在就需要为id_num增加非聚集索引,添加了非聚集索引后,会给id_num进行排序(内部使用结构为B+树),并且排序后,我只需要查询此目录(即查询B+树),很快就知道为id为56的在数据库中的第67条,而不需要在去遍历表中的所有数据。 所以,在非聚集索引中,不重复的数据越多,那么索引的效率越高。 + +1.2.3按照数据唯一性分类:唯一索引、非唯一索引 +1.2.4按键列个数区分:单列索引,多列索引 +1.2.5其他分类:索引视图、包含性列索引、全文索引、XML索引等 +1.3创建索引 +1.3.1创建聚集索引:一般建立主键的时候自动生成 +create CLUSTERED INDEX 索引名称 ON 表名(字段名) +1.3.2创建非聚集索引 +create NONCLUSTERED INDEX 索引名称 ON 表名(字段名) +1.3.3 + +--索引名:IX_, IDX_ + +--删除指定约束 +alter table 表名 +drop constraint 主键约束名称 + +--将指定字段设置成主键非聚集索引 + +alter table 表名 +add constraint 主键约束名称 primary key NONCLUSTERED(字段名) + +--fillfactor 填充因子 一页需要填充 % 数据 默认是0 + +--单列:索引列中只有一个字段 +--多列:索引中有多个字段 + +--多列索引需要符合最左原则:根据创建的索引列顺序,按照从左到右的顺序查询, \ No newline at end of file