SQL操作相关脚本生成:
用SQL的管理器上可以右键任务还原,然后设置需要恢复的数据库名以及需要转移的文件名以及其它选项,然后点击上面的转出脚本,这样给出的脚本就是最标准的
查看所有表名
select name from sysobjects where type='U'
查询表的所有字段名
Select name from syscolumns Where ID=OBJECT_ID('表名') select * from information_schema.tables select * from information_schema.views select * from information_schema.columns
sqlsever 主键
SELECT tab.name AS [TABLE_NAME], col.name AS [COLUMN_NAME], idx.name AS [CONSTRAINT_NAME] FROM sys.indexes idx JOIN sys.index_columns idxCol ON (idx.object_id = idxCol.object_id AND idx.index_id = idxCol.index_id) JOIN sys.tables tab ON (idx.object_id = tab.object_id) JOIN sys.columns col ON (idx.object_id = col.object_id AND idxCol.column_id = col.column_id);
sqlserver 外键表
select A.name as 外键关联的表,B.name as 外键所在的表,C.name as 外键名称 from sysforeignkeys inner join sysobjects A on A.id=sysforeignkeys.fkeyid inner join sysobjects B on B.id=sysforeignkeys.rkeyid inner join sysobjects C on C.id=sysforeignkeys.constid
本文作者为新逸网络,转载请注明。