简体   繁体   English

如何在SQL Azure中设置外键?

[英]How do you set up a foreign key in SQL Azure?

How do you set up a foreign key in SQL Azure? 如何在SQL Azure中设置外键?

I have a database now on the Azure system. 我现在在Azure系统上有一个数据库。

The tables in the database have an intended use such that there is one main, logically centralized table and then there are a number of tables which each describe some column in the main table. 数据库中的表具有预期用途,使得存在一个主要的逻辑集中表,然后存在多个表,每个表描述主表中的一些列。 For example, if I have an age classification column in the main table, I might have a separate table which lists some categories of the age classification (as a string) and some associated index. 例如,如果我在主表中有一个年龄分类列,我可能会有一个单独的表,其中列出了年龄分类的一些类别(作为字符串)和一些相关的索引。 Then the index from the age classification table would be used as a reference in the main table. 然后,年龄分类表中的索引将用作主表中的参考。

Is this what a foreign key is? 这是外键吗? Is there some way in SQL Azure to make the association between these indexes? SQL Azure中是否有某种方法可以在这些索引之间建立关联?

yep - that's what a foreign key is. 是的 - 这就是外键。

Perhaps the easiest way is using t-sql in a SSMS query window 也许最简单的方法是在SSMS查询窗口中使用t-sql

alter table MyTable
add constraint MyTable_MyColumn_FK FOREIGN KEY ( MyColumn ) REFERENCES MyOtherTable(MyOtherIDColumn)

(from: How do I create a foreign key in SQL Server? ) (来自: 如何在SQL Server中创建外键?

SQL Azure is different from other SQL Servers in some respects, but not in terms of this simple command. SQL Azure在某些方面与其他SQL Server不同,但在这个简单命令方面则不同。

I found the SQL Azure Migration Wizard invaluable for converting 'normal' sql to Azure SQL. 我发现SQL Azure迁移向导对于将“普通”sql转换为Azure SQL非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM