[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 ...
随机推荐
- iOS边练边学--通知机制和键盘处理小练习
一.发送通知 NSNotification *note = [NSNotification notificationWithName:@"通知的名称,随便写,例如:你妈叫你回家吃饭" ...
- scp基本使用方法
scp基本使用方法: scp用于在两台电脑之间进行数据的copy,形式如下: 第一种, scp [-r] 文件/文件夹 user@host:dir ,需要输入密码. 第二种, scp [-r] ...
- Hibernate- 开发环境准备
数据库:两张表,两者通过publisher_id构成关联关系. Book(图书表) CREATE TABLE `t_book` ( `id` int(11) NOT NULL AUTO_INCREME ...
- MySql C++调用库Connector/c++编译 和 接口封装【三】Connector/c++ 使用总结及封装
工程需要加上各个路径: 库使用需要几个文件: 1.include 文件夹 c/c++ /常规/附加包含目录 Connector/c++ 的安装版里面的Include 文件夹.或者把 /driver以及 ...
- daterangepicker 使用方法总结
daterangepicker 是一个时间段选择插件.官网地址:http://www.daterangepicker.com/ 项目中需要实现如下图的效果: 1.引入该插件所需要的JS 和 CSS , ...
- Spark 快速理解
转自:http://blog.csdn.net/colorant/article/details/8255958 ==是什么 == 目标Scope(解决什么问题) 在大规模的特定数据集上的迭代运算或重 ...
- 【转】【C#】全局键盘监听
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi ...
- java_Observer Design Pattern
摘自: http://www.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html Creating Your Own Event, Source ...
- jquery -- 删除节点
jQuery提供了三种删除节点的方法,即remove(),detach()和empty(). 测试所用HTML代码: <p title="选择你最喜欢的水果?">你最喜 ...
- c++ const enum #define
最后的最后,我们略微总结一下: 1.只是声明单一固定值,尽可能采用const. 2.如果是一组固定值,并且互相有关联,则采用enum. 3.不涉及条件编译,只 ...