• 获取数据库表详细信息、存储过程、视图、的sql


    select s.[name] + '.' + t.[name] as tablename
                                    from sys.tables as t,sys.schemas as s 
                                    where t.schema_id = s.schema_id
                                    and s.[name] = @dbo
                                    order by tablename
    获取指定架构下的所有表
    SELECT 
                            (case when a.colorder=1 then d.name else '' end) 表名,
                            a.colorder 字段序号,
                            a.name 字段名,
                            (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then ''else '' end) 标识,
                            (case when (SELECT count(*) 
                            FROM sysobjects 
                            WHERE (name in (SELECT name
                            FROM sysindexes
                            WHERE (id = a.id) AND (indid in (SELECT indid
                            FROM sysindexkeys
                            WHERE (id = a.id) AND (colid in (SELECT colid
                            FROM syscolumns
                            WHERE (id = a.id) AND (name = a.name))))))) AND (xtype = 'PK')) > 0 then '' else '' end) 主键,
                            b.name 类型,
                            a.length 占用字节数,
                            COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
                            isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
                            (case when a.isnullable=1 then ''else '' end) 允许空,
                            isnull(e.text,'') 默认值,
                            isnull(g.[value],'') AS 字段说明    
    
                            FROM  syscolumns a 
                            left join systypes b on a.xtype=b.xusertype
                            inner join sysobjects d on a.id=d.id  and  d.xtype='U' and d.name<>'dtproperties'
                            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  
                            where  d.uid = 1
                            --where d.name in ('Contact','StockBmps','AddressType')---查询具体的表,注释掉后就是查询整个数据库了
                            order by a.id,a.colorder 
    获取数据库所有表字段详细信息
    select c.name ColumnName,t.name ColumnType from sys.columns c,sys.tables tb,sys.types t
                                    where c.object_id = tb.object_id
                                    and c.system_type_id = t.system_type_id
                                    and tb.name = @tableName
                                    and t.name <> 'sysname'
                                    order by c.column_id
    获取指定表下的所有列和其类型
    select s.[name] + '.' + v.[name] as viewname 
                                    from sys.views as v,sys.schemas as s 
                                    where v.schema_id = s.schema_id
                                    and s.[name] = @dbo
                                    order by viewname
    获取指定架构下的所有视图
    select s.[name] + '.' + p.[name] as procname 
                                    from sys.procedures as p,sys.schemas as s 
                                    where p.schema_id = s.schema_id
                                    and s.[name] = @dbo
                                    order by procname
    查询指定架构下的所有存储过程
    SP_HELPTEXT @procname
    获取存储过程行形式的内容
  • 相关阅读:
    sqlserver建立临时表
    动态引用WebService
    技术的力量:30分钟的动画片和《彗星撞地球》超炫的动画 仅64K
    sqlserver2005新功能函数
    使用面向对象的、完整的单点登录功能
    asp.net上传功能(单文件,多文件,自定义生成缩略图,水印)
    C#对字符和文件的加密解密类
    JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
    JavaScript表格隔行换色悬停高亮
    Javascript模拟c#中arraylist操作(学习分享)
  • 原文地址:https://www.cnblogs.com/aweifly/p/3408927.html
Copyright © 2020-2023  润新知