请注意鳄鱼:sql server2005 存储数据库表名、字段名、描述的数据库表和sql语句
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 20:58:55
--查询表名,字段名,描述
SELECT
A.name AS table_name,
B.name AS column_name,
C.value AS column_description
FROM sys.tables A
INNER JOIN sys.columns B
ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C
ON C.major_id = B.object_id
AND C.minor_id = B.column_id
WHERE A.name = 'MuMu'--查询表的字段名,字段类型等
SELECT c.name,t.name,c.xprec,c.xscale,c.isnullable
FROM systypes t,syscolumns c
WHERE t.xtype=c.xtype
AND c.id = (SELECT id FROM sysobjects WHERE name='c_bill')
ORDER BY c.colid;--后面这两个没试验,不知道对不对也不知道什么用
--主键(参考SqlServer系统存储过程sp_pkeys):
select COLUMN_NAME = convert(sysname,c.name)
from
sysindexes i, syscolumns c, sysobjects o
where o.id = object_id('[YourTableName]')
and o.id = c.id
and o.id = i.id
and (i.status & 0x800) = 0x800
and (c.name = index_col ('[YourTableName]', i.indid, 1) or
c.name = index_col ('[YourTableName]', i.indid, 2) or
c.name = index_col ('[YourTableName]', i.indid, 3) or
c.name = index_col ('[YourTableName]', i.indid, 4) or
c.name = index_col ('[YourTableName]', i.indid, 5) or
c.name = index_col ('[YourTableName]', i.indid, 6) or
c.name = index_col ('[YourTableName]', i.indid, 7) or
c.name = index_col ('[YourTableName]', i.indid, 8) or
c.name = index_col ('[YourTableName]', i.indid, 9) or
c.name = index_col ('[YourTableName]', i.indid, 10) or
c.name = index_col ('[YourTableName]', i.indid, 11) or
c.name = index_col ('[YourTableName]', i.indid, 12) or
c.name = index_col ('[YourTableName]', i.indid, 13) or
c.name = index_col ('[YourTableName]', i.indid, 14) or
c.name = index_col ('[YourTableName]', i.indid, 15) or
c.name = index_col ('[YourTableName]', i.indid, 16)
)--外键:
select t1.name,t2.rtableName,t2.name
from
(select col.name, f.constid as temp
from syscolumns col,sysforeignkeys f
where f.fkeyid=col.id
and f.fkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t1 ,
(select OBJECT_NAME(f.rkeyid) as rtableName,col.name, f.constid as temp
from syscolumns col,sysforeignkeys f
where f.rkeyid=col.id
and f.rkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t2
where t1.temp=t2.temp
SELECT
A.name AS table_name,
B.name AS column_name,
C.value AS column_description
FROM sys.tables A
INNER JOIN sys.columns B
ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C
ON C.major_id = B.object_id
AND C.minor_id = B.column_id
WHERE A.name = 'MuMu'--查询表的字段名,字段类型等
SELECT c.name,t.name,c.xprec,c.xscale,c.isnullable
FROM systypes t,syscolumns c
WHERE t.xtype=c.xtype
AND c.id = (SELECT id FROM sysobjects WHERE name='c_bill')
ORDER BY c.colid;--后面这两个没试验,不知道对不对也不知道什么用
--主键(参考SqlServer系统存储过程sp_pkeys):
select COLUMN_NAME = convert(sysname,c.name)
from
sysindexes i, syscolumns c, sysobjects o
where o.id = object_id('[YourTableName]')
and o.id = c.id
and o.id = i.id
and (i.status & 0x800) = 0x800
and (c.name = index_col ('[YourTableName]', i.indid, 1) or
c.name = index_col ('[YourTableName]', i.indid, 2) or
c.name = index_col ('[YourTableName]', i.indid, 3) or
c.name = index_col ('[YourTableName]', i.indid, 4) or
c.name = index_col ('[YourTableName]', i.indid, 5) or
c.name = index_col ('[YourTableName]', i.indid, 6) or
c.name = index_col ('[YourTableName]', i.indid, 7) or
c.name = index_col ('[YourTableName]', i.indid, 8) or
c.name = index_col ('[YourTableName]', i.indid, 9) or
c.name = index_col ('[YourTableName]', i.indid, 10) or
c.name = index_col ('[YourTableName]', i.indid, 11) or
c.name = index_col ('[YourTableName]', i.indid, 12) or
c.name = index_col ('[YourTableName]', i.indid, 13) or
c.name = index_col ('[YourTableName]', i.indid, 14) or
c.name = index_col ('[YourTableName]', i.indid, 15) or
c.name = index_col ('[YourTableName]', i.indid, 16)
)--外键:
select t1.name,t2.rtableName,t2.name
from
(select col.name, f.constid as temp
from syscolumns col,sysforeignkeys f
where f.fkeyid=col.id
and f.fkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t1 ,
(select OBJECT_NAME(f.rkeyid) as rtableName,col.name, f.constid as temp
from syscolumns col,sysforeignkeys f
where f.rkeyid=col.id
and f.rkey=col.colid
and f.constid in
( select distinct(id)
from sysobjects
where OBJECT_NAME(parent_obj)='YourTableName'
and xtype='F'
)
) as t2
where t1.temp=t2.temp
sql server2005 存储数据库表名、字段名、描述的数据库表和sql语句
Navision采用SQL Server2005作为数据库配置
SQL server2005 无法连接到数据库
数据库基本----SQL语句大全
数据库基本----SQL语句大全
推荐:监控数据库性能的SQL语句汇总
数据库基本----SQL语句大全123
数据库基本----SQL语句大全11
数据库设计 - 设计表和字段
MS SQL 数据库备份和还原的几种方法
Sql Server数据库的备份和恢复措施
ASP连接SQL数据库
SQL Server 数据库备份
培训公司/机构-供应SQL SERVER2005数据库系统管理与开发培训 尽在慧聪网
数据库基本sql语句 - 自强不息 厚德载物 - ITeye技术网站
随机提取Access/SqlServer数据库中的10条记录的SQL语句
转载:ADO连接SQL数据库
SQL Server 2000数据库收缩
常用SQL语句书写技巧 - SQL Server - 数据库 - 程序员之家
关于存储过程的ADO调用的一些心得(输出参数,返回值)-数据库专栏,SQL Server-...
关于SQL固定服务器角色和固定数据库角色
c# 本地和远程连接数据库SQL和ACCESS的字符串
解决SQL数据库日志已满的问题
SQL Server数据库日志已满的解决方法