博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
存储过程
阅读量:4464 次
发布时间:2019-06-08

本文共 2210 字,大约阅读时间需要 7 分钟。

-----------全选 create【创建】 procedure 【存储过程名】usp_GetAllStudents as  select【查询】 *【*代表所有的列】 from【表名】 student go -----------根据主键查询 create【创建】 procedure 【存储过程名】usp_GetStudentById ( @StudentId int )【括号里为参数,为用户提供值】 as  select【查询】 *【*代表所有的列】 from 【表名】student 【条件】where  go ------------新增 create【创建】 procedure 【存储过程名】usp_InsertStudent ( @StudentName nvarchar(50), @StudentGender bit, @StudentBirthday Date )【括号里为参数,为用户提供值】 as  insert【插入】 into 【表名】student

 【需要插入的值】values(@StudentName,@StudentGender,@StudentBirthday)  select @@IDENTITY【用获取主键列的值】 go -------------修改 create【创建】 procedure 【存储过程名】usp_UpdateStudent ( @StudentId int, @StudentName nvarchar(50), @StudentGender bit, @StudentBirthday Date )【括号里为参数,为用户提供值】 as  update 【表名】student

 set 【要修改的信息】

,

,

StudentBirthday=@StudentBirthday 【修改的条件】

where  go -------------删除 create【创建】 procedure 【储存过程名】usp_DeleteStudent (  @StudentId int ) as  delete【删除】 from 【表】student 【删除条件】where  go ------知识补偿

1.实现多条数据插入 insert to 表名 select '值1','值2','值3' union select '值1','值2','值3' union select '值1','值2','值3'

 

2.实现表结构跟表数据拷贝(前提创建一个新表出来) select * into 新表 from 旧表

 

3.实现向一张表插入另一张表的数据 inert into 新表 (列1,列2,列3) select 列1,列2,列3 from 旧表 【注释】插入中文值建议数值前加N,可以防止乱码(针对Nvarchar类型) 如:N"张三"

 

4.Truancate删除和Delete删除的区别

【语法】:Truncate table 表名 【Truncate与Delete语句区别】1.delete 语句删除数据时候,自动编号没有恢复默认值,Trancate可以恢复默认

值                             2.delete 语句可以通过where条件进行删除,Trancate必须删除所有语句                             3.truncate语句删除数据时,速度跟性能比delete语句高得很多,好的多(Truncate删除不会记录日记,Delete可以记录日志)                             4.Truncate语句删除数据时,不会触发触发器,Delete语句可以

 

5.Union 和 UnionAll连接表的使用与区别

Union 【语法】:Select UName,Age from userInfo where age<=10   Union   Select UName,Age from UserInfo where age>=20 【注释】:Union会取消冗余项

 

Union all 【语法】:Select UName,Age from userInfo where age<=10   Union all   Select UName,Age from UserInfo where age>=20

【注释】:1.连接显示的字段个数必须一致,类型必须一致           2.Union All 不会取消冗余项           3.建议使用Union All

 

6.拷贝表结构但是没有数据 【语法】: select top 0* into 新表 from 旧表

insert into 表名 output inserted.列名 values('值'.'值')

7.Select语句先后顺序,还有游标

在SqlServer中有顺序的集合可以成为游标 在SqlServer中的表可以视为集合,可以Select,Ordey by 【注释】:Ordey by之后集合(表)就不能成为集合了,可以添加top实现集合效果 在SqlServer中语句执行顺序 form--->where--->groud by---->having--->select--->order by 【注释】:having 筛选的列名来至Select 映射列 【注释】:Select里面顺序Distinct,Top,Select

转载于:https://www.cnblogs.com/heweihong/p/5355496.html

你可能感兴趣的文章
leetcode中的python学习
查看>>
sqlserver打开对象资源管理器管理的帮助文档的快捷键
查看>>
JBOSSAS 5.x/6.x 反序列化命令执行漏洞(CVE-2017-12149)
查看>>
Zookeeper zkui-zookeeper图形化管理工具
查看>>
java运行时内存分类
查看>>
为什么说 Git 比 SVN 更好
查看>>
1.基础数据类型的初识 字符串 bool 整型 if else elif
查看>>
【设计模式】4、原型模式
查看>>
进入meta模式关闭背光灯
查看>>
webstorm上svn的安装使用
查看>>
【JEECG技术文档】数据权限自定义SQL表达式用法说明
查看>>
使用 Bootstrap Typeahead 组件
查看>>
linux_cacti 配置之 安装snmp 服务
查看>>
201407-至今
查看>>
c# 应用事务
查看>>
优化杭州某著名电子商务网站高并发千万级大型数据库经验之- SQL语句优化(转)...
查看>>
WPF——TargetNullValue(如何在绑定空值显示默认字符)
查看>>
Linux之crontab
查看>>
清除浮动
查看>>
CenOS+宝塔(模拟)上线博客项目
查看>>