1、获取所有数据库名:
SELECT Name FROM Master..SysDatabases ORDER BY Name
2、获取某个数据库的所有表名:
SELECT Name FROM DatabaseName..SysObjects Where XType='U' ORDER BY Name
3、获取某个表的所有字段名:
SELECT Name FROM SysColumns WHERE id=Object_Id('TableName')
4、获取数据库所有数据类型:
select name from systypes
5、获取主键字段:
SELECT name FROM SysColumns WHERE id=Object_Id('表名') and colid=(select top 1 keyno from sysindexkeys where id=Object_Id('表名'))
6、查询用户创建的所有数据库:
SELECT name FROM SysColumns WHERE id=Object_Id('表名') and colid=(select top 1 keyno from sysindexkeys where id=Object_Id('表名'))
或
select dbid, name AS DB_NAME from master..sysdatabases where sid <> 0x01
7、查询某一个表的字段和数据类型:
select column_name,data_type from information_schema.columns
where table_name = '表名'
8、修改数据库的名称:
sp_renamedb 'old_name', 'new_name'
9、只复制一个表结构,不复制数据:
select top 0 * into [t1] from [t2]