摘要: namespace 执行语句存储过程{ public static class SqlHelper { static readonly string constr = ConfigurationManager.ConnectionStrings["Myconstr"].ConnectionString; public static int ExecuteNoneQuery(string sql,CommandType cmdType,params SqlParameter[] p ) { using (SqlCon... 阅读全文
posted @ 2014-02-26 21:10 我叫小菜 阅读(317) 评论(0) 推荐(0) 编辑
摘要: --1.减少网络传输--2.杜绝sql注入攻击(无论是带参数的sql语句与存储过程原理一样)--3.模块化设计--3已经编译好,直接执行,不需要检查语句,编译了,提高性能sp_helptext 'sp_tables' --以sp,xp开头的都是系统预定义的存储过程--exec sp_ helptext 'sp_renamedb'--用户自定义存储过程,一般用"Usp_"开头的命名 xp_cmdshell----------------------------------------------gocreate proc usp_hellowo 阅读全文
posted @ 2014-02-26 20:52 我叫小菜 阅读(193) 评论(0) 推荐(0) 编辑
摘要: --声明变量,同时为变量赋值declare @n int=10 print @n--单独使用一条语句为变量复制set @n=20print @nselect @n=30print @n--通过set赋值与select复制的区别select @n=COUNT(*) from Employeesprint @nset @n=(select COUNT(*) from Employees)--当使用set给变量赋值时。必须给查询语句用括号括起来print @nselect @n=TblStudent.tSAge from TblStudent --当使用select给变量赋值的时候,如果查询语句返回 阅读全文
posted @ 2014-02-26 20:48 我叫小菜 阅读(5162) 评论(0) 推荐(0) 编辑
摘要: ---------------------视图:对查询语句的封装--------------------视图就是对sql语句的封装create view vw_Empsasselect t1.AreaID, t1.AreaName, t2.AreaNAme as Area from TblArea as t1 inner join TblArea as t2 on t1.AreaPId=t2.AreaIdgoselect * from vw_Emps--视图并不存储数据,视图只是将sql语句封装了一下,所以最执行的还是sql语句,--若是表中的数据发生了变化,视... 阅读全文
posted @ 2014-02-26 20:46 我叫小菜 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 全表扫描:对数据进行检索效率最差的是全表扫描,就是一条一条的找。聚集索引索引的顺序与磁盘存储的顺序对应所以只能有一个聚集索引,否则磁盘存储的顺序就无法确定了非聚集索引索引的顺序与磁盘的存储顺序不对应逻辑顺序与物理顺序不一致索引意味着排序,排序后则可更高效的查询,但是因为索引也是占据空间的,而且添加、更新、删除数据的时候也需要同步更新索引,降低了插入和更新的效率依赖聚集索引不然就依赖磁盘存储的顺序填充引子 便于后期数据的插入,而不会改动过多的数据每页预留8kb,其实数据并存的数据并没有8kb,但便于后期的数据的插入逻辑读取:从缓存中读取数据。物理读取:从磁盘中读取数据预读取:一种性能优化机制,在 阅读全文
posted @ 2014-02-26 20:43 我叫小菜 阅读(193) 评论(0) 推荐(0) 编辑
摘要: -----------------------独立子查询,相关子查询---------------------一个查询的结果集作为另一个查询的查询源,这个查询的结果集需要起一个别名--独立子查询,内部的子查询可以独立运行,没有涉及到外部查询的任何数据select * from(select ... 阅读全文
posted @ 2014-02-26 20:37 我叫小菜 阅读(346) 评论(0) 推荐(0) 编辑
摘要: namespace 省市联动_递归_{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { CreateTreeNode(0,treeView1.Nodes); } private List GetAreaNameById(i... 阅读全文
posted @ 2014-02-26 20:32 我叫小菜 阅读(779) 评论(0) 推荐(0) 编辑
摘要: namespace 对TblPerson增删查改_Sqlhelp_{ public static class SqlHelp { static readonly string constr = ConfigurationManager.ConnectionStrings["... 阅读全文
posted @ 2014-02-26 20:30 我叫小菜 阅读(406) 评论(0) 推荐(0) 编辑
摘要: public partial class Form1 : Form { string constr; public Form1() { InitializeComponent(); constr = "Data Source=MGLI217RZIKKH6B;Initial Catalog=Itcast2014;Integrated Security=True"; } private void btnAdd_Click(object sender, EventArgs e) ... 阅读全文
posted @ 2014-02-26 20:24 我叫小菜 阅读(278) 评论(3) 推荐(0) 编辑
摘要: ----case--------说明:当我们在查询的时候,需要显示的不是表中列的值,而是根据列值显示其他值--(1)区间判断----select-- 要显示的自定义列名-- case when 条件判断 then 需要显示的值-- when...-- else...-- end-- (2)等级判断--select ---case 列名 -- when 列值 then 需要显示的值 -- else 需要显示的值 -- endselect * from BBSUsersselect [uId], name, 等级=[lev... 阅读全文
posted @ 2014-02-26 20:16 我叫小菜 阅读(937) 评论(0) 推荐(0) 编辑
摘要: --1.类型转换convert() cast()--convert(data_type,expression,[style]) 注意:对于时间转换,只能用convert() print convert(varchar(16),getdate(),120)--cast(expression as data_type)print convert(varchar(16),getdate(),120)--2.union()联合结果集--union指的是联合的意思,是将多个结果联合成一个结果集,把所有的记录都--加起来编程一个大的结果集--可以union的前提:每个结果集的列的个数都得一致 ... 阅读全文
posted @ 2014-02-26 20:06 我叫小菜 阅读(15418) 评论(0) 推荐(0) 编辑
摘要: -------------查询表中的数据--------------1.下面的语句表示查询MyStudent表中的所有行、所有列 select * from Mystudent--2.只显示部分列的数据(显示所有行,但是只查看指定的列) select fname,fage,fgender from MyStudent--3.select语句中请查询出年龄在20-23岁之间的所有女同学的姓名,年龄,性别,学号 select fname,fage,fgender,fid from MyStudent where fage>=20 and fage=20 and fage=20 a... 阅读全文
posted @ 2014-02-26 19:56 我叫小菜 阅读(1190) 评论(0) 推荐(0) 编辑
摘要: -creat Database named MyDatabase--Create Database MyDatabase--delete Datacase named MyDatabase--Drop Database MyDatabase--use sql with Parameters to create databseCreate Database MyFirstDBon Primary (--name file name='MyFirstDB', filename='D:\MyFirstDB.mdf',--若是放在c盘,有可能会有权限不足的问题,需要放在 阅读全文
posted @ 2014-02-26 19:54 我叫小菜 阅读(5079) 评论(0) 推荐(0) 编辑