查询Sql Server数据库对象结构

  1. 查询数据库
  2. 查询架构
  3. 查询表
  4. 查询列
  5. 查询存储过程
  6. 查询视图

1.查询某一服务器下所有数据库

select t.[name] as 数据库
from sys.databases as t
order by name

2.查询某一数据库的架构

select name as 架构,
schema_id as 架构Id
--,principal_id
from sys.schemas
where principal_id = 1;

3.查询某一数据库的表

select s.name+'.'+t.name as 表,
t.object_id as 表Id
from sys.tables as t
inner join sys.schemas as s on t.schema_id = s.schema_id and s.principal_id=1

4.查询某一数据库的所有的列

select
s.name as 架构,
d.NAME as 表,
A.NAME as 列,
COLUMNPROPERTY( a.id,a.name,'IsIdentity') as 是否为自增, --0非自增 1自增
B.NAME AS 数据类型,
COLUMNPROPERTY(A.ID,A.NAME,'PRECISION') AS 精度,
ISNULL(COLUMNPROPERTY(A.ID,A.NAME,'Scale'),0) AS 保留位,
A.ISNULLABLE AS 是否为空, -- 0空 1非空,
ISNULL(E.TEXT,'') as 默认值,
ISNULL(g.[value],'') AS 列说明
FROM syscolumns a
LEFT JOIN systypes b ON a.xtype=b.xusertype
INNER JOIN sys.objects d ON a.id=d.object_id AND d.type='U'AND d.name<>'dtproperties'
inner join sys.schemas as s on d.schema_id=s.schema_id
LEFT JOIN syscomments e ON a.cdefault=e.id
LEFT JOIN sys.extended_properties g ON a.id=g.major_id AND a.colid=g.minor_id
LEFT JOIN sys.extended_properties f ON d.object_id=f.major_id AND f.minor_id =0

5.查询存储过程

select
s.Name as 架构,
p.Name as 存储过程,
sm.definition as 存储过程内容
from sys.procedures as p
inner join sys.sql_modules sm ON p.object_id = sm.object_id
inner join sys.schemas as s on p.schema_id=s.schema_id

6.查询视图

select
s.name+'.'+t.name as 视图,
t.object_id as 视图Id
from sys.views as t
inner join sys.schemas as s on t.schema_id = s.schema_id and s.principal_id=1

查询Sql Server数据库对象结构的更多相关文章

  1. 查询SQL SERVER数据库日志工具

    在SQL SERVER中查看操作日志,一直是一个比较麻烦的事情,因为微软并没有提供直接的系统工具可以查看日志内容,虽然可以通过非正式的隐藏接口dbcc log 获取日志的非解析编码但是要还原是个非常麻 ...

  2. 何查询SQL Server数据库没有主键的表并增加主键

    SQL Server数据库中,如果一个表没有主键,我们该如何查询呢?本文我们主要就介绍了如何查询数据库中没有主键的表名并为其增加主键的方法,希望能够对您有所帮助. 该功能的实现代码如下: declar ...

  3. SQL Server 数据库对象命名参考

    一. 引言 编码规范是一个优秀程序员的必备素质,然而,有很多人非常注重程序中变量.方法.类的命名,却忽视了同样重要的数据库对象命名.这篇文章结合许多技术文章和资料,以及我自己的开发经验,对数据库对象的 ...

  4. 通过sys.objects查询SQL SERVER数据库改动内容

    适用于: SQL Server 2008 + .Azure SQL 数据库.Azure SQL 数据仓库.并行数据仓库 系统视图sys.objects,在数据库中用户定义(创建)的每个架构范围对象(例 ...

  5. 基于Python的SQL Server数据库对象同步轻量级实现

    缘由 日常工作中经常遇到类似的问题:把某个服务器上的某些指定的表同步到另外一台服务器.类似需求用SSIS或者其他ETL工作很容易实现,比如用SSIS的话就可以,但会存在相当一部分反复的手工操作.建源的 ...

  6. 获取sql server数据库表结构

    if exists (select 1 from sysobjects where name = 'sysproperties'and xtype = 'V')begin    DROP VIEW s ...

  7. 查询SQL SERVER 数据库版本号脚本语句

    数据库直接执行此语句即可select @@version 示例: Microsoft SQL Server 2014 - 12.0.2000.8 (X64)   Feb 20 2014 20:04:2 ...

  8. PHP odbc查询SQL SERVER数据库带有中文时无返回数据

    近日遇到一个小麻烦当数据库中有中文字符数据 结果odbc_fetch_array后 我用json_encode怎么也得不到数据页面一片空白 我脑子也一片空白后来才知道sqlserver 没有 UTF- ...

  9. 一段后台C#查询SQL Server数据库代码

    using System; using System.Data; using System.Collections.Generic; using System.Linq; using System.W ...

随机推荐

  1. vlookup返回多个结果

    http://www.360doc.com/content/12/1021/15/7665211_242782107.shtml =IFERROR(VLOOKUP(D2&ROW(A1),IF( ...

  2. unigui的编译部署

    unigui的编译部署 unigui既可以EXE形态部署,也可以IIS的ISAPI的形态部署.关键在工程文件.dpr里面的编译开关. {$define UNIGUI_VCL} // 注释此编译开关将使 ...

  3. ExternalException (0x80004005): GDI+ 中发生一般性错误

    .net开发的程序用了一个自绘的框架, 平常部署到IIS上都没有问题,今天突然之间这个功能就运行不起来了. 报错:GDI+错误,然后在本地的VS里面运行是没有问题的 百度出来的改Path环境变量.注册 ...

  4. 设置UITableView分割线距左边的间距

    ``` [self.tableView setSeparatorInset:UIEdgeInsetsZero]; [self.tableView setLayoutMargins:UIEdgeInse ...

  5. 中科大debian 9 + docker源设置

    wget https://mirrors.ustc.edu.cn/repogen/conf/debian-http-4-stretch -O sources.list sudo apt-get ins ...

  6. Rabbit MQ 入门指南

    rabbitMQ是一个在AMQP协议标准基础上完整的,可服用的企业消息系统.他遵循Mozilla Public License开源协议.采用 Erlang 实现的工业级的消息队列(MQ)服务器. Ra ...

  7. nginx root&alias 文件路径配置

    nginx 指定文件路径有两种方式 root 和 alias,root 与 alias 主要区别在于 nginx 如何解释 location 后面的 uri,这会使两者分别以不同的方式将请求映射到服务 ...

  8. [vuejs] 终端npm run dev 不能自动打开浏览器运行项目解决办法

    终端执行: npm run dev 出现: I Your application is running here: http://localhost:8080 但并没有打开浏览器运行项目 解决办法: ...

  9. 【原创】Your Connection is not private

    用Chrome打开google等https网站时碰到问题: “your connection is not private”. 后来发现是跟GoAgent的安全证书有关系(我用XX.NETFQ) 解决 ...

  10. opencv实现canopy算法

    #include "stdafx.h" using namespace cv; int main(int argc, char** argv) { Mat img=imread(& ...