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

相关推荐
wqq_99225027721 分钟前
ssm面向品牌会员的在线商城小程序
数据库·小程序
呼啦啦呼啦啦啦啦啦啦2 小时前
在win10环境部署opengauss数据库(包含各种可能遇到的问题解决)
数据库
m0_748230213 小时前
mysql约束和高级sql
数据库·sql·mysql
刘艳兵的学习博客3 小时前
刘艳兵-DBA046-ASSM表空间的全表扫描范围由哪些因素综合确定?
数据库·sql·oracle·刘艳兵
2401_857636393 小时前
实验室管理技术革新:Spring Boot系统
数据库·spring boot·后端
生活很暖很治愈3 小时前
C51数字时钟/日历---LCD1602液晶显示屏
数据库·单片机·mongodb
YONG823_API3 小时前
1688商品数据采集API的测试对接步骤分享(提供免费测试key)
开发语言·数据库·爬虫·python·数据挖掘
码上一元4 小时前
掌握 Spring 事务管理:深入理解 @Transactional 注解
数据库·spring
程序猿毕设源码分享网4 小时前
基于springboot停车场管理系统源码和论文
数据库·spring boot·后端
YiSLWLL4 小时前
Django+Nginx+uwsgi网站使用Channels+redis+daphne实现简单的多人在线聊天及消息存储功能
服务器·数据库·redis·python·nginx·django