sql是一个标准,而T-SQL是microsoft公司对这个标准的实现。
Transact-SQL在关系数据库管理系统中实现数据的检索,操作和添加功能。
T-SQL语言分为三种类型:
数据定义语言:如 create ,drop,
数据操作语言:如:insert,update.
数据控制语言:
变量和常量
常量是不需要声明的,如:数字1
变量又分为了局部变量和全局变狼。
![](https://img.haomeiwen.com/i2655509/f24342daa0a0ef6e.png)
![](https://img.haomeiwen.com/i2655509/1b5243ec45020943.png)
![](https://img.haomeiwen.com/i2655509/6b40889d09dc670a.png)
创建视图
![](https://img.haomeiwen.com/i2655509/ab46df74729ca680.png)
用语言创建视图
create view V_class1
as
select b.childClass_Type,b.childClass_Pntroduce
from tb_Class a,tb_ChildClass b
where a.class_Id=b.class_Id
视图的开头要V开头
select * from V_class1
运算符
算数运算符: +,-,*,/,%
&:位于逻辑运算符
|:位或运算符
^:位异运算符
比较运算符:
![](https://img.haomeiwen.com/i2655509/c0dcabc8321180b3.png)
![](https://img.haomeiwen.com/i2655509/a3d2cbaf592acbcb.png)
表达式
![](https://img.haomeiwen.com/i2655509/e8556db569aec261.png)
注释
注释的作用就是增强代码的可读性。
注释主要描述程序的名称,作者的名称,变量说明,代码更改日期,算法描述。
![](https://img.haomeiwen.com/i2655509/66f164df71a654c3.png)
if else
![](https://img.haomeiwen.com/i2655509/bffc4b034a126d44.png)
declare @num int select @num=AVG(fenshu) from T_student where kaoshi_Num='0203' and kecheng_Num='345' select @num if @num>=80 begin print '这门课程老师教的好' end else print '这门课老师还需要提高'
![](https://img.haomeiwen.com/i2655509/77e476854b056a8e.png)
if else嵌套语句
![](https://img.haomeiwen.com/i2655509/60b967107f911dc6.png)
case语句
![](https://img.haomeiwen.com/i2655509/ad2918e194c3ae3b.png)
![](https://img.haomeiwen.com/i2655509/ad061adc8cf3df35.png)
while语句
![](https://img.haomeiwen.com/i2655509/bbc822169030b0b5.png)
![](https://img.haomeiwen.com/i2655509/1bfd4dd3aefbad68.png)
![](https://img.haomeiwen.com/i2655509/12f0f122eac73027.png)
while语句示例
waitfor语句
![](https://img.haomeiwen.com/i2655509/7c1fc77a61816417.png)
![](https://img.haomeiwen.com/i2655509/9e4690bca27e9f96.png)
GOTO语句
用goto语句来执行重复的语句。
存储过程的创建
![](https://img.haomeiwen.com/i2655509/4ba9d603fbe05598.png)
简单的创建一个存储过程
![](https://img.haomeiwen.com/i2655509/7ed5b4cc62da6154.png)
![](https://img.haomeiwen.com/i2655509/c52ea32beac1fbe1.png)
Goto语句是跳转的意思,用于重复功能
declare@Counterint;
set@Counter=1
while@Counter<10
begin
print@Counter
set@Counter=@Counter+1
if@Counter=4gotoBeach_One
if@Counter=5gotoBeach_Two
end
Beach_One:
print'Jumping To Beach One'
gotoBeach_Three
Beach_Two:
print'Jumping To Beach Two'
Beach_Three:
print'Jumping To Beach Three'
结果是:
1
2
3
Jumping To Beach One
Jumping To BeachThree
一个表两个列作为主键,叫做组合主键。组合主键一般不建议使用,因为后期比较麻烦。
一般选择什么样的列作为主键?
[if !supportLists]1. [endif]选择不会被修改的列。
[if !supportLists]2. [endif]选择单列,不要选择那些组合咧
[if !supportLists]3. [endif]选择那些简单的列,(整数列,自动编号)。
网友评论