[SQL] 常用查询脚本
查询哪些存储过程使用了某个表
select b.name from syscomments a,sysobjects b where a.id=b.id and a.text LIKE '%ftblogkpicontentnew%'
查询某个存储过程被哪些语句使用过
declare @object nvarchar(400)
set @object='up_ReportMst_Insert'
select routine_name,routine_definition,routine_type
from information_schema.routines
where routine_definition like '%'+@object+'%'
order by routine_type
select routine_name,routine_definition,routine_type
from information_schema.routines
where routine_definition like '%'+@object+'%'
order by routine_type
select *
from sysobjects o, syscomments s
where o.id = s.id
and text like '%'+@object+'%'
and o.xtype = 'P'
select *
from sysobjects o, syscomments s
where o.id = s.id
and text like '%'+@object+'%'
and o.xtype = 'P'
查询某个数据库表约束
use ArisamCafe
go
SELECT sysobjects.id objectId,OBJECT_NAME(sysobjects.parent_obj) tableName,
sysobjects.name constraintName, sysobjects.xtype AS constraintType,
syscolumns.name AS columnName
FROM sysobjects INNER JOIN sysconstraints
ON sysobjects.xtype in('C', 'F', 'PK', 'UQ', 'D')
AND sysobjects.id = sysconstraints.constid
LEFT OUTER JOIN syscolumns ON sysconstraints.id = syscolumns.id
--WHERE OBJECT_NAME(sysobjects.parent_obj)='tb_PrjServiceSell'
use ArisamKW
go
EXEC sp_helpconstraint 'tb_PrjServiceSell'
根据现有表获取更新脚本
select 'update ArisamDB.dbo.tb_Items set url=N''' +isnull((cast(y.urlNew as nvarchar(MAX))),'')
+''' where companycode=N''' +isnull((cast(y.companycode as nvarchar(MAX))),'')
+''' and listid=N'''+isnull((cast(y.listid as nvarchar(MAX))),'')
+''' and itemid=N'''+isnull((cast(y.itemid as nvarchar(MAX))),'')
+''''
,''
from ( select a.companycode as companycode,a.listid as listid,a.itemid as itemid,REPLACE(a.url,a.oldve,a.newve) as urlNew
from [ArisamKW].[dbo].[MIG_Items] as a,
ArisamDB.dbo.tb_Items as b
where a.companycode=b.CompanyCode
and a.listid=b.listid
and a.itemid=b.ItemID) as y
根据现有表获取插入脚本
SELECT TOP 10 'INSERT INTO [EntDA].[dbo].[tb_DeliveryAssets] VALUES (N'''+ CONVERT(nvarchar(36),[DeliveryID])+''''
+',N''' +isnull((cast([DeliveryAssetType] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Title] as nvarchar(MAX))),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[ServiceCode])),'') +''''
+',N''' +isnull((cast([LanguageID] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Countrys] as nvarchar(MAX))),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[ResCgyCode] )),'') +''''
+',N''' +isnull((cast([ProjectCode] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([ProjectName] as nvarchar(MAX))),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[FunctionCode] )),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[BizTypeCode] )),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[SolutionCode] )),'') +''''
+',N''' +isnull((cast([ItemType] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([OwnerDept] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Contents] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([NamoKey] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([AttachType] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Url] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Title] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([SecurityLevel] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([ReadAuthXml] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([KMTag] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([KnowledgeCategory] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Writer] as nvarchar(MAX))),'') +''''
+',N''' +isnull((convert(nvarchar(23),[WriteDate],21)),'') +''''
+',N''' +isnull((cast([LastEditor] as nvarchar(MAX))),'') +''''
+',N''' +isnull((convert(nvarchar(23),[LastEditDate],21)),'') +''''
+',N''' +isnull((cast([SaveState] as nvarchar(MAX))),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[ResourceCode])),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[CategoryCode] )),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[ActivityCode] )),'') +''''
+',N''' +isnull((CONVERT(nvarchar(36),[TaskCode])),'') +''''
+',N''' +isnull((cast([ReadCount] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([RecommandCode] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([IsMailSend] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([ICT_Service] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([Writer2] as nvarchar(MAX))),'') +''''
+',N''' +isnull((cast([LastEditor2] as nvarchar(MAX))),'') +''''
+',N''' +isnull((CONVERT(nvaRCHAR(36),[DeliveryID2] )),'') +''''
+',N''' +isnull((convert(nvarchar(23),[LastEditDate2],21)),'') +''')'
,''
FROM [EntDA].[dbo].[tb_DeliveryAssets]
[SQL] 常用查询脚本的更多相关文章
- sql常用查询命令
目录 SQL Server常用查询命令: 查看当前时间 查询所有数据库名 查询当前使用的数据库名 查询前几条数据 去重查询 字段换名 查询不等于 查询在两个值之间数据 查询条件或 模糊匹配查询 查询为 ...
- SQL常用查询语句及函数
1.日期匹配_获取时间差 select datediff(dd,getdate(),'12/25/2006') --计算从今天到12/25/2006还有多少个月 2.不能通过IP连接数据库 在数据库 ...
- sql 常用操作脚本代码
,--运行fy_mh库[use] use fy_mh ,--查询 mh_dblj表 select * from mh_dblj ,--更新 某个字段(把表的某个字段下的所有的数据清空)[update ...
- MySQL - 常用命令及常用查询SQL
常用查询SQL #查看临时目录 SHOW VARIABLES LIKE '%tmp%'; #查看当前版本 SELECT VERSION(); 常用命令 #查看当前版本,终端下未进入mysql mysq ...
- 浅谈MySQL中优化sql语句查询常用的30种方法 - 转载
浅谈MySQL中优化sql语句查询常用的30种方法 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使 ...
- 数据库基本查询语句(SQL常用增删改查语句 简单复习 mark)
SQL常用增删改查语句 1增 1.1[插入单行]insert [into] <表名> (列名) values (列值)例:insert into Strdents (姓名,性别,出生日期) ...
- oracle常用查询sql
oracle常用查询sql 原创 gordon陈 发布于2018-05-10 22:32:18 阅读数 297 收藏 展开 #!/bin/sh## create by Gordon Chen echo ...
- 【转载】C#常用数据库Sqlserver通过SQL语句查询数据库以及表的大小
在Sqlserver数据库中,一般我们查看数据库的大小可以通过查找到数据库文件来查看,但如果要查找数据表Table的大小的话,则不可通过此方法,在Sqlserver数据库中,提供了相应的SQL语句来查 ...
- Sql常用语法以及名词解释
Sql常用语法以及名词解释 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) D ...
随机推荐
- Javascript实现浏览器菜单命令
每当我们看到别人网页上的打开.打印.前进.另存为.后退.关闭本窗口.禁用右键等实现浏览器命令的链接,而自己苦于不能实现时,是不是感到很遗憾?是不是也想实现?如果能在网页上能实现浏览器的命令,将是多么有 ...
- C++隐式转换与显式转换
普通类型的转换顺序:隐式把char——>int和从short——>double.转换可能会导致数据的丢失. 自定义类型:有两种函数可以进行隐式转换,单参数构造函数 和 隐式类型转换符. ...
- maven pom.xml 详解(注释版)
转自:http://mrlee23.iteye.com/blog/1806412 pom.xml <project xmlns="http://maven.apache.org/POM ...
- 关于Nginx里面的配置文件里面的location参数的意思
location是指当遇到这个单词的时候,把root改成大括号里面的值,再把单词和后面的路径加上root变成总的文件路径进行搜索,如果没有location,直接把root加上域名后面的路径变成总的文件 ...
- 不可在 for 循环体内修改循环变量,防止 for 循环失去控制
不可在 for 循环体内修改循环变量,防止 for 循环失去控制. #include <iostream> /* run this program using the console pa ...
- 在windows下编译x264
最近因为各种原因,对流媒体的学习,突然中断在了编码这块.今天难得静下心来,从新拿起了代码. 对encode这边,因为之前虽然也接触了,也找了两个例子,但目前还没真正开始,所以先从编译x264这个库开始 ...
- css -- 背景图片自适应屏幕大小
由于<body>标签的图片不能够拉伸, 解决办法: 1.图片不够大,又background属性不能拉伸图片: 2.只能用个div,把其z-index值设为负,并使这个div大小为整个bod ...
- VMware下Ubuntu与宿主Windows共享文件夹 (转至 http://blog.csdn.net/zz962/article/details/7706755)
概述 1.安装VMware Tool 2.设置共享 步骤 开始安装VMware Tool 显示如下画面(如果宿主无法访问外网,可能会出现一个更新失败,可以无视之) 通过下列命令解压.执行,分别是下面的 ...
- struct iphdr中的__LITTLE_ENDIAN_BITFIELD和__BIG_ENDIAN_BITFIELD
__LITTLE_ENDIAN_BITFIELD表示小端序,__BIG_ENDIAN_BITFIELD表示大端序. /usr/include/linux/ip.h中有一段代码定义了ip首部的结构体,例 ...
- php纯原生实现数组二分法
代码如下 $arr = [1,3,5,7,9];//$arr = range(1,10000);var_dump(find($arr, 2)); function find(array $arr, $ ...