SQL Azure不支持information_schema,但它支持sys。*表(至少是您需要的)。
http://msdn.microsoft.com/en-us/library/ee336238.aspx#catalog
您可以使用以下方法:
Select * from sys.foreign_keys fk
inner join sys.foreign_key_columns fkc on fkc.constraint_object_id = fk.object_id
为了让您获得列参与或索引信息查看以下表格SYS SYS.TABLES,SYS.INDEXES和sys 。列。标准的sys目录视图比使用ANSI标准的视图要难一些。
我在评论中谈到的数据库触发器如下。这并不处理在表create上创建fk的实例,但可以轻松扩展以处理其他情况。这将确保此信息始终准确实施为ddl触发器
--drop trigger test on database
create trigger test on DATABASE
for ALTER_TABLE,RENAME
AS
set nocount on
--get XML event and extract table and schema
DECLARE @data XML
SET @data = EVENTDATA()
declare @idoc int
EXEC sp_xml_preparedocument @idoc OUTPUT, @data
--indicate if table needs to be reloaded
declare @boolean bit
set @boolean = 0
--check conditions where keys change
SELECT @boolean = 1
FROM OPENXML (@idoc, '/EVENT_INSTANCE/AlterTableActionList/Create/Constraints',2) x
SELECT @boolean = 1
FROM OPENXML (@idoc, '/EVENT_INSTANCE/AlterTableActionList/Drop/Constraints',2) x
if @boolean =1
begin
--Create the table initially with below line
--select * into MyInformationSchemaFKs from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
--Reloads the table if there are constraint changes
truncate table MyInformationSchemaFKs
insert into MyInformationSchemaFKs
select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
end
EXEC sp_xml_removedocument @idoc
go
您不应该复制任何内容!那些系统目录视图随处可用 - 无需复制.... – 2011-04-11 11:00:37