SQL SERVER 语句技巧
来源:互联网 发布:淘宝网店店铺介绍范文 编辑:程序博客网 时间:2024/06/11 09:11
-----查询 触发器
select name from sysobjects where name=触发器名称 and xtype='TR'
----创建触发器
create trigger tr_tb_dailinotice_status
on catabill
for insert
as
update tb_dailinotice_status set num=0
from tb_dailinotice_status,inserted
where
rtrim(ltrim(tb_dailinotice_status.username))=rtrim(ltrim(inserted.username))
---查询用户表
select name from sysobjects where xtype='U';--批量创建表
declare @tempTag VARCHAR(100)
declare @count int
--多列定义 declare @tempTag1 VARCHAR(100)
--多列.....
declare tagCursor cursor for (select name from sysobjects where xtype='U')--读取行数据到游标
open tagCursor--打开游标
fetch next from tagCursor INTO @tempTag--多列定义加,@temp
WHILE(@@FETCH_STATUS = 0) BEGIN--0:FETCH 语句成功。 -1:FETCH 语句失败或此行不在结果集中。 -2:被提取的行不存在。
print @tempTag
fetch next from tagCursor INTO @tempTag--多列定义加,@temp
select @count=count(*) from sysobjects where xtype='U' and name=@tempTag+'_c'
IF(@count=0)exec('select * into '+ @tempTag+'_c from '+@tempTag)
END
close tagCursor--关闭游标
DEALLOCATE tagCursor--销毁游标
----查询某用户的表
select so.name from sysobjects so,sysusers su where so.uid=su.uid and su.name='sg' and so.xtype='U';
-----批量删除表
declare @tempTag VARCHAR(100)
--多列定义 declare @tempTag1 VARCHAR(100)
--多列.....
declare tagCursor cursor for (select so.name from sysobjects so,sysusers su where so.uid=su.uid and su.name='sg' and so.xtype='U')--读取行数据到游标
open tagCursor--打开游标
fetch next from tagCursor INTO @tempTag--多列定义加,@temp
WHILE(@@FETCH_STATUS = 0) BEGIN--0:FETCH 语句成功。 -1:FETCH 语句失败或此行不在结果集中。 -2:被提取的行不存在。
print @tempTag
fetch next from tagCursor INTO @tempTag--多列定义加,@temp
exec('drop table '+@tempTag)
END
close tagCursor--关闭游标
DEALLOCATE tagCursor--销毁游标
- SQL SERVER 语句技巧
- SQL Server SQL语句调优技巧(1)
- (小技巧)Sql server查看sql语句的执行时间
- sql语句优化技巧 sql 语句技巧
- 技巧-----sql语句拼接
- SQL语句技巧点滴
- SQL语句使用技巧
- SQL语句特殊技巧
- SQL语句收集--技巧
- SQL语句书写技巧
- SQL 语句的技巧
- SQL语句技巧汇总
- SQL语句小技巧
- sql语句使用技巧
- SQL语句技巧
- sql 语句技巧
- sql语句技巧
- sql语句技巧
- 跨越技术困难
- 基于Bootsplash嵌入式Linux启动画面定制
- myeclipse svn插件subclipse使用http代理同步svn时出现异常
- 类装载记录和application,plugin摘要
- JSTL 核心标签库的使用
- SQL SERVER 语句技巧
- 1011. World Cup Betting
- 使用画刷画图
- java 使用相对路径读取文件
- 中国互联网移动互联网消费者分析
- myeclipse8.5安装findbugs插件
- 关于Contiki中Rime代码的一些分析记录
- 分享一个GSM短信猫接口程序
- 【Android 开发教程】修改首选项文件的默认名字