刚才看了看系统表的相关信息,其实还是有很多方法的,呵呵!
--
SELECT b.NAME AS fkName,
c.NAME AS fkTable,
e.NAME AS fkColName,
d.NAME AS pkTable,
f.NAME AS pkColName,
a.*
FROM sysreferences AS a
JOIN sysobjects AS b ON a.constid = b.id
JOIN sysobjects AS c ON a.fkeyid = c.id
JOIN sysobjects AS d ON a.rkeyid = d.id
JOIN syscolumns AS e ON a.fkeyid = e.id AND e.colid = a.fkey1
JOIN syscolumns AS f ON a.rkeyid = f.id AND f.colid = a.rkey1
WHERE b.type = 'F'
SELECT b.NAME AS fkName,
c.NAME AS fkTable,
e.NAME AS fkColName,
d.NAME AS pkTable,
f.NAME AS pkColName,
a.*
FROM sysreferences AS a
JOIN sysobjects AS b ON a.constid = b.id
JOIN sysobjects AS c ON a.fkeyid = c.id
JOIN sysobjects AS d ON a.rkeyid = d.id
JOIN syscolumns AS e ON a.fkeyid = e.id AND e.colid = a.fkey1
JOIN syscolumns AS f ON a.rkeyid = f.id AND f.colid = a.rkey1
WHERE b.type = 'F'
对上面的查询语句再加以游标处理,也可以实现批量重命名外键。
通过这件事也让我认识到加深对系统表理解的重要性。