视图

视图就是我们查询出来的虚拟表
创建视图:create view 视图名
as
SQL查询语句,分组,排序,in 等都不能写
视图的用法: select * from 视图名

SQL编程

定义变量:declare @变量名 数据类型 declare @a int
变量赋值:set @变量名 = 值 set @a=10

select @a --直接打印在结果框中
set @a = 10 --也是赋值,不打印

select @a; --打印在结果集中
print @a; --打印在消息框中

-----------------------------------------------------
查汽车表中名称含有宝马两个字的
declare @name varchar(20)
set @name='宝马'
select * from car where Name like '%'+@name+'%'

查汽车表中所有汽车的平均值并输出
declare @price decimal(10,4)
select @price = AVG(Price) from Car
print '所有汽车的平均价格为:'+cast(@price as varchar(20))

-----------------------------------------------------

if ... else 的用法,if后面没有小括号,花括号用begin end 替代

if 判断条件
begin
要执行的语句
end
else
begin
要执行的语句
end

-----------------------------------------------------
declare @a int
declare @b int
declare @c int

set @a =10;
set @b =5;

if @a>@b
begin
set @c = @a + @b;
end
else
begin
set @c = @a - @b;
end
print @c
-----------------------------------------------------
C#里的Switch case 变形到数据库里用法

declare @ccname varchar(20)
set @ccname = '宝马'
select * from Car where Name like

case --switch...case的开头
when @ccname='宝马' then '%宝马%'
when @ccname='奥迪' then '%奥迪%'
else '%'
end --switch...case的结尾

-----------------------------------------------------
循环:
注意循环四要素

declare @str varchar(20)
set @str = '你好'
declare @i int
set @i = 1

while @i<=10
begin
print @str + cast (@i as varchar(20))
set @i = @i + 1
end

whie(条件)
{
循环体
}

-----------------------------------------------------
注意:语句结束之后不要写分号或逗号

最新文章

  1. 帆软报表FineReport中数据连接之Jboss配置JNDI连接
  2. resultset 对象获取行字段数据时报:java.sql.SQLException: Column &#39;id&#39; not found.
  3. List,Set,Map用法以及区别
  4. 【Python之路Day12】网络篇之Paramiko
  5. 放到u-boot/arch/arm/inlcude下面解压A20固件库制作笔记
  6. SD卡驱动分析(一)
  7. ubuntu 11.10 安装apache2 tomcat6
  8. 函数lock_rec_get_nth_bit
  9. HTML——表格table标签,tr或者td
  10. JavaScript--对象+函数
  11. HDU 3660 Alice and Bob&#39;s Trip
  12. 解决百度Ueditor编辑器表格不显示边框问题
  13. Bing必应(Yahoo雅虎)搜索引擎登录网站 - Blog透视镜
  14. gitLab添加ssh key
  15. wikioi 1034 家 实时动态的网络流量(费用流)
  16. 设置自己Eclipse代码风格(内部)
  17. 利用ZYNQ SOC快速打开算法验证通路(5)——system generator算法IP导入IP integrator
  18. Web程序报错:Error instantiating servlet
  19. easyui 信息提示
  20. python isinstance()方法的使用

热门文章

  1. Layui动画、按钮、表单
  2. P1614 爱与愁的心痛
  3. CE310A
  4. linux命令dmesg查看进程被杀死原因
  5. 【python】一些好的学习网址
  6. WebLogic(12C)——简单公布和JDBC
  7. linux下常用快捷方式
  8. openstack (3)---------部署memcached缓存服务,keystone服务
  9. android application类简单介绍(一)
  10. 【EasyUI】——可编辑的DataGrid