question

xarzu avatar image
xarzu asked

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

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?
sql-azure
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Grant Fritchey avatar image
Grant Fritchey answered
You create a foreign key in Azure databases the same way as you create them in SQL Server. For the parent table, you need to have either a primary key constraint or a unique index (unique constraint, same thing). Either of those can be used to define a relationship to a child key called a foreign key. Here's a more complete explanation of exactly [what you're asking about][1]. You can get the syntax and a full explanation of the T-SQL statements [here in the books online][2]. [1]: http://msdn.microsoft.com/en-us/library/ms175464(v=SQL.105).aspx [2]: http://msdn.microsoft.com/en-us/library/ms177463(v=sql.105).aspx
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.