天津七七一网站建设有限公司怎么样,网站域名注册价格,品牌建设最高境界是培育客户成为,北京物联网app开发公司1.索引添加索引#xff0c;设计界面#xff0c;在任何一列前右键--索引/键--点击进入添加某一列为索引 2.视图 视图就是我们查询出来的虚拟表创建视图#xff1a;create view 视图名 as SQL查询语句,分组#xff0c;排序#xff0c;in 等都不能写视图的用法#xff1a; s… 1.索引添加索引设计界面在任何一列前右键--索引/键--点击进入添加某一列为索引 2.视图 视图就是我们查询出来的虚拟表创建视图create view 视图名 as SQL查询语句,分组排序in 等都不能写视图的用法 select * from 视图名 3.SQL编程 定义变量declare 变量名 数据类型 declare a int变量赋值set 变量名 值 set a10 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 Carprint 所有汽车的平均价格为cast(price as varchar(20)) if ... else 的用法if后面没有小括号花括号用begin end 替代 if 判断条件begin 要执行的语句endelsebegin 要执行的语句end declare a intdeclare b intdeclare c int set a 10;set b 5; if abbegin set c a b;endelsebegin set c a - b;endprint 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 intset i 1 while i10begin print str cast (i as varchar(20)) set i i 1end whie(条件){ 循环体} 注意语句结束之后不要写分号或逗号 常用函数 1.数学函数操作一个数据返回一个结果 --取上限ceilingselect code,name,ceiling(price) from car ; --取下限 floorselect floor(price) from car --ABS 绝对值 --派 PI()圆周率括号里不需要加东西 --ROUND 四舍五入select ROUND(3.76,0) --SQRT 开根号 --SQUARE 平方乘以自己 2.字符串函数 --转换大写 upperselect upper(pic) from car; --转换小写 lower --去空格select ltrim ( 123 ) 去左空格 select 123123 可以不查数据直接这样显示出来 --space() 里面放几个数字就打印出来几个空格 --LEFT类似于SubString从左边开头截取select LEFT(123456,3); --len长度select len(aaaaaa); 返回几个长度 --replace 替换select replace(aaaaabbaaaaa,bb,haha);把第一个字符串中的bb替换成haha --reverse 翻转select reverse(abc); 结果是 cba --字符串转换函数 strselect str1.567,3,1;把1.567转换成字符串最多留3位小数点算一位保留小数点后1位 --字符串截取 SUBSTRINGselect substring(abcdefg,2,3);从第2位开始截取3位索引从1开始 3.时间日期函数 --获取当前系统时间 GetDate()select getdate(); sysdatetime() 获取数据库服务的时间戳 --获取年月日 year month dayselect year(1999-1-1); --判断日期是否正确isdate 返回bitselect isdate(2000-2-31)返回bit类型false是0true是1 --添加时间 dateaddselect dateadd(year,5,2000-1-1);添加什么类型加多少给谁加 --返回星期几 datename返回的值是字符串select datename(weekday,2000-1-1); 也可以返回第几天按月select datename(day,2000-1-1); 一年中第几天select datename(dayofyear,2000-1-1); datepart 一样可以返回周几但是返回的是int类型 转载于:https://www.cnblogs.com/blueteasama/p/5816607.html