markdown 在线制作ppt json校验和格式化工具

Sql Server 知识


1 1,
2 打开关系图
3 alter authorization on database:: dataname to sa
4 2.
5 check约束
6 例:列名 like '%@%' 对email 的格式
7 and ,in (),between and ,
8 3,
9 删除主表之前,必须先删除子表
10 4
11 比较运算符
12 =>,=,<=,,!,
13 5,
14 通配符
15 '_' 一个字符
16 % 任意长度字符
17 [] 括号中指定范围内的任意一个字符
18 [^] 不在括号中指定范围内的任意一个字符
19 例:手机号码:telcode like'13[5-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
20 6,
21 逻辑表达式
22 not ,and ,or
23 7,
24 insert 单行插入数据,数据值的数目必须和列数相等。并且,不能为标识列指定值,因为他的数值是自动增长的。
25 同时不能违反约束。
26 8
27 一次多行插入
28 (1)通过 insert select 语句将现有表中的数据添加到新表中(此表要实现创建好)
29 insert into newtablename( new table de 列)
30 select oldtable 列 from oldtablename
31 注意:顺序
32 9
33 通过select into 语句将现有的表中的数据添加到新表中
34 select oldtable 列 into newtable from oldtable
35 10,
36 通过union 关键字和数据进行多行插入
37 insert into tablename 列
38 select value union
39 select value union
40 select value
41 11
42 更新数据
43 update tablename set [where ]
44 12
45 delete
46 delete from tablename where
47 delete 只删除整条记录,
48 Truncate table 删除表中的所有行,功能上类似于没有where 的Delete语句,只删除表中的记录,而不删除标的结构。
49 Drop table删除整个数据库
50 13
51 Select
52 查询空值
53 select * from where
54 在查询中使用常量
55 select 姓名=name,地址=address from userinfotable
56 在查询中返回限制的行数。
57 select top 5 name , sex. saddress from userinfotable where sex=o
58 14,
59 查询中排序
60 select studentID as 学员编号,(Score*0.9) as 综合成绩
61 from Score where (Score*0.9)>60 order by score (desc-降序,asc-升序)
62 15
63 查询使用的函数
64 日期函数
65 getDate();取得当前时间
66 dateAdd ();将指定数值添加到指定的日期部分的日期,
67 Datediff();两个日期之间的指定日期部分的区别。
68 Datename();日期指定部分的字符串形式,
69 DatePart();日期中指定日期部分的整数形式。
70 系统函数
71 Convert
72 select Convet(varchar(10),123456)
73 Current_user 当前用户名
74 system_user 返回当前登录用户名
75 常用字符串函数
76 Charindex ();寻找一个字符在一个字符串中的起始位置
77 Len();返回传递给他的字符串的长度,
78 Ltrim(Rtrim());清楚字符串两边的空格
79 Replace('字符串的''要替换掉的字符','要现实的字符')
80 Stuff('字符串''2','3','要显示的字符串');在一个字符串中删除指定长度的字符,并在该位置插入一个新的字符串,
81 16,
82 使用in在列举值内进行查询
83 列:
84 select name as 姓名,from studet是where address in('上海','广州','上海'),
85 17
86 SQl server 中的聚合函数
87 sum, avg, count
88 18
89 分组
90 select ScoreID avg(Score) from as 课程平均成绩
91 from score
92 group by ScoreID
93 19
94 使用Haveing 字句进行分组筛选
95 select student as 学号,CourseID As 内部测试, avg(Score) as 内部测试平均成绩
96 from Score
97 group by studentiD CourseID
98 haveing count(score)>1
99 having 和where 子句可以在同一个语句中一起使用。
100 20
101 form 子句join on 内连接 inner Join on ,外连接 outer join on
102 21,
103 数据类型:
104 int 4 个字节 smallint 占用 2 个字节 tinyint 占用一个字节
105 浮点型: numeric 和 decimal 使用这种类型时(固定精度和范围的数值类型) 使用时必须指定范围和精度
106 范围时小数点左右所能存储的数字的总位数,精度时小数点右边存储的数字的位数。
107 22
108 约束
109 primary key,unique,Check,default,foreign key 约束
110
111
112
113 创建约束
114 alter table tablename
115 add constraint 约束 列
116 删除约束
117 drop constraint
118 23
119 创建登录帐户
120 exec sp_addlogin ,密码
121 创建数据库用户
122 exec sp_grantdbaccess '登陆帐户','数据库用户'
123 给数据库用户授权
124 grant insert ,update ,select on tablename to 数据库用户
125
126
127
128 grant create table to 数据库用户
129 24
130 变量
131 局部变量申明:declared @name type
132 赋值
133 select @name=name from userinfo where
134 set @name='';
135 25,
136 输出语句
137 print 局部变量或者是字符
138 和 select 局部变量as自定义列名
139 26
140 全局变量
141 @@error ,最后一个错误的错误号,
142 @@identify ,最后一次插入的标识値
143 @@language ,当前使用的语言名称
144 @@Max_connections,可以创建的连接的最大数目
145 @@Rowcount,受上一个SQl语句影响的行数
146 @@servername,本地服务器的名称
147 @@Servicename ,该计算机上的SQl服务的名称
148 @@Timeticks,该计算机上的每刻读的微妙数
149 @@Transcount,当前连接打开的事物数,
150 @@versin ,SQLserver 的版本信息
151 27
152 逻辑控制语句
153 if-else 条件语句
154 if 条件 begin 语句 end else begin 语句 end
155 28,
156 while 循环语句
157 while 条件 begin 语句 (可以有continue 和 break)end
158 29
159 case when then end
160 主要时对结果的操纵,
161 30
162 高级查询
163 子查询
164 in ,not in 效率高
165 exists ,not exists 效率低
166 31
167 事物,索引,视图
168 事物是单个工作单元
169 具有:原子性,一致性,隔离性,持久性。
170 开始事务:begin transaction
171 提交事务:commit transaction
172 回滚事物:rollback transaction
173
174
175
176 显示事物:用begin transaction 明确指定事物的开始
177 隐式事物:通过设置set implicit transactions on 语句将隐式事物的模式设置打开
178 通过判断@@error 是否等于零来执行回滚事物或是 提交事务
179 32
180 索引:唯一索引,主键索引,聚集索引,非聚集索引
181 if exists (select *From sysindexes where name ='xi_biao_lie')
182 drop index table.xi_biao_lie
183 go
184 create nonclustered index xi_biao_lie
185 on table(lie)
186 with fillfactor=30
187 go
188
189
190
191 使用索引
192 select * from table with xi_biao_lie where
193 33
194 视图
195 创建视图
196 use databasename
197 go
198 if exists (select * from sysobjects where name='view_table_lie')
199 drop view view_table_lie
200 go
201 create view view_table_lie
202 as
203 select 姓名=stuName,学号=stuinfo.stuno,笔试成绩=writenExam,
204 from stuinfo left join stumarks on
205 go
206 使用
207 select * from view_table_lie
208 34
209 存储过程
210 use studb
211 go
212 if exists (select * from sysobjects where name='proc_stu')
213 drop proc proc_stu
214 go
215 create proc proc_stu
216
217
218
219 此处可以创建输入或输出变量(数据类型)
220 输出变量 一定要有output
221 @Written int--输入参数
222 @lab int
223 as
224 select stuName,userinfo, werittenexam, labexam, from stuinfo
225 innet join stumarks on stuinfo.stuno=stumarks.stuno
226 where writtenExam<@writtenpass or labexamgo
227 调用
228 exec proc_stu 56,60
229 35,
230 抛出错误
231 Raiserror('错误信息',错误级别,数量)
232 return
233 36,
234 set nocount on 取消打印影响的行数。
注:本文非原创。
posted @ 2011-04-24 23:15  GavinHacker  阅读(251)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具