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

邮差的信 提交于 2019-12-13 13:24:10

问题


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

I have a database now on the Azure system.

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?


回答1:


yep - that's what a foreign key is.

Perhaps the easiest way is using t-sql in a SSMS query window

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 Azure is different from other SQL Servers in some respects, but not in terms of this simple command.

I found the SQL Azure Migration Wizard invaluable for converting 'normal' sql to Azure SQL.



来源:https://stackoverflow.com/questions/12384966/how-do-you-set-up-a-foreign-key-in-sql-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!