--获取所有数据库名:
SELECT name FROM master..sysdatabases WHERE name NOT IN ( 'master', 'model', 'msdb', 'tempdb', 'northwind','pubs' )
--获取某数据库的所有表:
SELECT name FROM YiDianTongV2..sysobjects Where xtype='U' ORDER BY name
--获取所有表名
--XType='U':表示所有用户表;
--XType='S':表示所有系统表;
--获取某表所有字段名:
SELECT * FROM syscolumns WHERE id=Object_Id('AdminsBase')
--获取数据库所有类型
select name from systypes
--获取某表的主键字段
SELECT name FROM syscolumns WHERE id=Object_Id('AdminsBase') and colid IN(SELECT keyno from sysindexkeys WHERE id=Object_Id('AdminsBase'))
--存储过程获取主键
exec sp_helpindex 'AdminsBase'
--获取字段类型
select a.name as [column],b.name as type from syscolumns a,systypes b where a.id=object_id('AdminsBase') and a.xtype=b.xtype
--或者可以通过存储过程
exec sp_help AdminsBase
--取表结构
SELECT c.TABLE_SCHEMA ,
c.TABLE_NAME ,
c.COLUMN_NAME ,
c.DATA_TYPE ,
c.CHARACTER_MAXIMUM_LENGTH ,
c.COLUMN_DEFAULT ,
c.IS_NULLABLE ,
c.NUMERIC_PRECISION ,
c.NUMERIC_SCALE
FROM [INFORMATION_SCHEMA].[COLUMNS] c
WHERE TABLE_NAME = 'AdminsBase'
网友评论