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 取消打印影响的行数。

注:本文非原创。

转载于:https://www.cnblogs.com/gavinsp/archive/2011/04/24/2026566.html

Sql Server 知识相关推荐

  1. SQL Server:定时作业的设置方法

    如果在SQL Server 里需要定时或者每隔一段时间执行某个存储过程或3200字符以内的SQL语句时,可以用管理->SQL Server代理->作业来实现.  1.管理->SQL  ...

  2. 讲解SQL Server定时作业job的设置方法

    如果在SQL Server 里需要定时或者每隔一段时间执行某个存储过程或3200字符以内的SQL语句时,可以用管理->SQL Server代理->作业来实现. ◆1.管理->SQL ...

  3. 视频教程-数据库SQL查询,最佳案例讲解-SQL Server

    数据库SQL查询,最佳案例讲解 教学风格独特,以学员视角出发设计课程,难易适度,重点突出,架构清晰,将实战经验融合到教学中.讲授技术同时传递方法.得到广大学员的高度认可. 王进 ¥19.00 立即订阅 ...

  4. 视频教程-sql server 系列课程数据库维护篇-SQL Server

    sql server 系列课程数据库维护篇 全栈工程师,2010年从事软件开发以及软件教育培训工作,至今将近十余年,在项目的开发,设计,到管理上积累了丰富的实战经验,教学风格上通俗易懂,问题解答环节一 ...

  5. 学 SQL Server 我最常逛的 5 个网站

    点击蓝色"有关SQL"关注我哟 加个"星标",天天与10000人一起快乐成长 很多读者加我微信,问的问题都很类似,"有没有好的书可以推荐", ...

  6. Analysis Services基础知识——深入SQL Server 2008

    Analysis Services基础知识 --深入SQL Server 2008 这一节中,我们将介绍Analysis Services的体系结构,这个体系结构在SQLServer2005中建立,并 ...

  7. SQL Server基础知识概念要点详细讲解

    SQL Server基础知识概念要点详细讲解 目录 基础概念 1.网状模型数据库 2.层次模型数据库 3.关系模型数据库 知识点实例总结 基础概念 SQL语言中,between and表示包括两边参数 ...

  8. SQL Server 2005“备份集中的数据库备份与现有的数据库不同”解决方法此信息转载自BlueSky's Blog,www.heuupk.com,为尊重无价的知识请保留此版权信息。...

    SQL Server 2005"备份集中的数据库备份与现有的数据库不同"解决方法 以前一直使用SQL Server2000,现在使用SQL Server2005,就在现在的项目中使 ...

  9. [转]SQL Server 索引基础知识(2)----聚集索引,非聚集索引

    SQL Server 索引基础知识(2)----聚集索引,非聚集索引 [来自]http://blog.joycode.com/ghj/archive/2008/01/02/113291.aspx 由于 ...

最新文章

  1. flink 自定义 窗口_Flink入门实战 (下)
  2. windows 10占用cpu和内存过高
  3. iOS开发- UICollectionView详解+实例
  4. ios php 推送测试工具,IOS PushNotification - IOS推送测试 PHP 版
  5. Elasticsearch(二)概念及安装、部署
  6. 监听localStorage变化(同页面监听)
  7. AOP 还在配置吗改用打标签模式吧!
  8. CSS中可继承的属性
  9. 红队技巧:绕过ESET_NOD32抓取密码(ESET_NOD32是一款杀毒软件)
  10. java面试准备题目
  11. 用c语言编写金山打字游戏,c#实现简单金山打字小游戏(源码)
  12. emqx-Clientid认证
  13. 用户金字塔模型的应用:知乎案例分析
  14. php方法帮助文档,Trace方法_帮助文档_Thinkphp手册
  15. 台式计算机有不有蓝牙,台式机没有蓝牙怎么办
  16. 3626 三元一次方程(枚举)
  17. 陈抟(tuán)《心相篇》
  18. 基金经理做场外期权的法律风险分析
  19. 树莓派编译ffmpeg支持x264硬解码播放视频
  20. granfana密码重置

热门文章

  1. 添加列oracle默认值,Oracle 11g增加列,并带默认值的新特性
  2. 一个500强公司的数据化运营管理实践
  3. 数据分析学习笔记—python_word处理及邮件发送
  4. python stdin和stdout_无法使用Python写入和读取stdin / stdout
  5. 关于四元数的个人理解
  6. 利用python进行数据分析——第11章时间序列
  7. 实验7.1 对Point类重载“++”(自增)、“–”(自减)运算符
  8. ~~KMP(数据结构)
  9. python自动处理下载的英文字幕
  10. Oracle11g x64使用Oracle SQL Developer报错:Unable to find a Java Virtual Machine