查询sql servser的视图、函数和存储过程、以及表和列

SELECT NAME as VIEW_NAME, OBJECT_DEFINITION (id) as VIEW_DEFINITION,'none' as CHECK_OPTION, '0' as IS_UPDATABLE,* FROM sysobjects WHERE xtype='V'

SELECT NAME as VIEW_NAME, OBJECT_DEFINITION (object_id) as VIEW_DEFINITION,'none' as CHECK_OPTION

FROM sys.views where schema_id in (SELECT schema_id FROM sys.schemas where name='dbo') ;

SELECT NAME as pro_NAME, OBJECT_DEFINITION (id) as VIEW_DEFINITION,'none' as CHECK_OPTION, '0' as IS_UPDATABLE,* FROM sysobjects WHERE xtype='p'

SELECT NAME as pro_NAME, OBJECT_DEFINITION (object_id) as VIEW_DEFINITION,'none' as CHECK_OPTION

FROM sys.procedures where schema_id in (SELECT schema_id FROM sys.schemas where name='dbo') ;

select sysobjects.name as OBJECT_NAME ,OBJECT_DEFINITION (id) AS DEFINITION , '' as CommentString from sysobjects where xtype in('FN','IF','TF')

函数要传数据库和schema

SELECT ROUTINE_NAME AS OBJECT_NAME, ROUTINE_DEFINITION AS DEFINITION, '' as CommentString,*

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_TYPE = 'FUNCTION' AND ROUTINE_CATALOG = 'master' and ROUTINE_SCHEMA ='dbo' ;

SELECT NAME as pro_NAME, OBJECT_DEFINITION (id) as VIEW_DEFINITION,'none' as CHECK_OPTION, '0' as IS_UPDATABLE,* FROM sysobjects WHERE xtype='p'

SELECT NAME as pro_NAME, OBJECT_DEFINITION (object_id) as VIEW_DEFINITION,'none' as CHECK_OPTION

FROM sys.tables where schema_id in (SELECT schema_id FROM sys.schemas where name='dbo') ;

select * from sys.objects where type='U';

select * from sys.tables

SELECT col.name FROM sys.columns col JOIN sys.objects obj ON col.object_id = obj.object_id WHERE obj.type = 'U' AND obj.name = 'orderDetails';

select * from sys.columns ;

CREATE PROCEDURE ssssss

AS

SET NOCOUNT ON;

SELECT OrderID

FROM orderDetails

WHERE OrderID IS NULL;

CREATE FUNCTION dbo.ufnGetInventoryStock(@ProductID int)

RETURNS int

AS

-- Returns the stock level for the product.

BEGIN

DECLARE @ret int;

SELECT @ret = SUM(p.Quantity)

FROM Production.ProductInventory p

WHERE p.ProductID = @ProductID

AND p.LocationID = '6';

IF (@ret IS NULL)

SET @ret = 0;

RETURN @ret;

END;

CREATE VIEW vOrders

AS

SELECT OrderID

FROM orderDetails

WHERE OrderID IS NULL;

相关推荐
十叶知秋20 分钟前
【jmeter】jmeter的线程组功能的详细介绍
数据库·jmeter·性能测试
瓜牛_gn2 小时前
mysql特性
数据库·mysql
奶糖趣多多3 小时前
Redis知识点
数据库·redis·缓存
CoderIsArt4 小时前
Redis的三种模式:主从模式,哨兵与集群模式
数据库·redis·缓存
师太,答应老衲吧6 小时前
SQL实战训练之,力扣:2020. 无流量的帐户数(递归)
数据库·sql·leetcode
Channing Lewis7 小时前
salesforce case可以新建一个roll up 字段,统计出这个case下的email数量吗
数据库·salesforce
毕业设计制作和分享8 小时前
ssm《数据库系统原理》课程平台的设计与实现+vue
前端·数据库·vue.js·oracle·mybatis
ketil278 小时前
Redis - String 字符串
数据库·redis·缓存
Hsu_kk9 小时前
MySQL 批量删除海量数据的几种方法
数据库·mysql
编程学无止境9 小时前
第02章 MySQL环境搭建
数据库·mysql