上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页
摘要: 创建 for触发器 use test gocreate trigger t1on afor insert,updateasinsert into b(name) values('a')在a表插入或更新数据后,在b表同时插入一条数据 阅读全文
posted @ 2012-05-11 08:38 高捍得 阅读(217) 评论(0) 推荐(1) 编辑
摘要: 事务 事务的点: 1.begin tran 是事务开始的地方,也是 事务回滚的起点.也就说他会忽略这个起点之后的最终没有提交的所有语句, 2.commit tran 事务的提交 是一个事务的终点 当发出 commit tran命令时,可以认为 该事务是 持久的. 撤销已完成事务的唯一方法 是 发出一个新的事务.从功能上而言,该事务 是对第一个事务的反转. 3.rollbac... 阅读全文
posted @ 2012-05-10 16:41 高捍得 阅读(558) 评论(0) 推荐(1) 编辑
摘要: 用户自定义函数 和存储过程是类似的, 是一组 有序的t-sql语句,udf被 预先优化和编译,并且可以作为一个单元来进行调用. 使用存储过程 时 可传入参数,传出参数.可以返回值,不过该值用于指示成功或者失败,而非返回数据.也可以返回结果集, 但是在没有将结果集插入到某种表(通常是临时表)中以供后面使用的情况下,不能在 查询中真正使用它们. 即使使用 表值 输出参数,在查询中使用结果之前... 阅读全文
posted @ 2012-05-10 13:22 高捍得 阅读(756) 评论(0) 推荐(1) 编辑
摘要: 数据库结构:表内的数据:自定义函数: 递归查出 树下所有节点 ,参数是 父id create function sss(@id as int) returns @t table ( id int not null, name int not null, pid int null ) as begin declare @lay as int; insert into @t select * from tree where pid =@id; select @lay = min(id) from tree where pid =@id; --第一次 @l... 阅读全文
posted @ 2012-05-10 12:28 高捍得 阅读(1106) 评论(0) 推荐(1) 编辑
摘要: 输入输出参数: 给存储过程传参数,叫做输入参数,用户告诉存储过程需要 利用这个参数干些什么. 输出参数: 从存储过程得到那些数据. 创建一个可选参数的存储过程: create proc pa1@name varchar(50)=NULLasif(@name is not null) select * from a where name like @name+'%';else... 阅读全文
posted @ 2012-05-09 17:36 高捍得 阅读(331) 评论(0) 推荐(1) 编辑
摘要: 存储过程: 做的就是 返回最后一次插入的标识列 id值 create proc pa2@id int outputasinsert into a(name) values('5')set @id=@@identity表: id 是标识列 ,后台代码: string cons = ConfigurationManager.ConnectionStrings["ApplicationS... 阅读全文
posted @ 2012-05-09 17:26 高捍得 阅读(161) 评论(0) 推荐(1) 编辑
摘要: 查看最后一行插入标识列的值 use testgoinsert into a(name) values('ss')declare @ident intselect @ident=@@identityselect @ident结果: 查看语句响应了多少行use test godeclare @rowCount intselect * from bselect @rowCount=@@rowcou... 阅读全文
posted @ 2012-05-09 16:25 高捍得 阅读(454) 评论(0) 推荐(1) 编辑
摘要: string con = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString(); StringBuilder sb = new StringBuilder(); sb.Append(" insert into a(name) values('... 阅读全文
posted @ 2012-05-09 14:25 高捍得 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 创建简单视图: use testgocreate view v1(视图名)asselect name from b 这样视图就创建好了. 下面说下视图的本质: 当执行 select * from v1 时, 那么实质上市告诉 sql server 把执行 select name from b 语句返回的结果 给我. 视图就像在命令执行的查询那样运行---没有任何的预先优化过程.这意味着数据在请... 阅读全文
posted @ 2012-05-09 13:21 高捍得 阅读(252) 评论(0) 推荐(1) 编辑
摘要: sql server的存储机制 区段: 是用来为表和索引 分配空间的基本存储单元. 由 8个连续的页面构成,大小为64kb. 区段的注意事项: 一旦区段已满,那么下一记录 将要占据的空间不是记录的大小,而是整个区段的大小. 通过预先分配空间,sql server节省了为每个记录分配新空间的时间 页: 页是在到达实际数据行 之前所能达到的最后一个存储级别.尽管每个区段中的页数是固定的,但是每... 阅读全文
posted @ 2012-05-08 17:40 高捍得 阅读(278) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 17 下一页