查询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;

相关推荐
f***R83 小时前
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException
java·数据库·sql
T***19203 小时前
实操解决Navicat连接postgresql时出现‘datlastsysoid does not exist‘报错的问题
数据库·postgresql
·云扬·3 小时前
Redis性能测试实战:掌握redis-benchmark工具用法与集群压测技巧
数据库·redis·缓存
2401_837088503 小时前
秒杀优化—基于 Redis 完成秒杀下单
数据库·redis·缓存
爬山算法4 小时前
Redis(144)Redis的Cluster的节点通信是如何实现的?
数据库·redis·缓存
AI绘画小334 小时前
Web 安全核心真相:别太相信任何人!40 个漏洞挖掘实战清单,直接套用!
前端·数据库·测试工具·安全·web安全·网络安全·黑客
I***26155 小时前
数据库操作与数据管理——Rust 与 SQLite 的集成
数据库·rust·sqlite
百***48075 小时前
redis连接服务
数据库·redis·bootstrap
C***11505 小时前
对基因列表中批量的基因进行GO和KEGG注释
开发语言·数据库·golang
小蒜学长6 小时前
基于spring boot的汽车4s店管理系统(代码+数据库+LW)
java·数据库·spring boot·后端·汽车