SQL Server Delete - Froregin Key
Posted
by Ahmet Altun
on Stack Overflow
See other posts from Stack Overflow
or by Ahmet Altun
Published on 2010-05-14T09:03:55Z
Indexed on
2010/05/14
9:14 UTC
Read the original article
Hit count: 239
I have got two tables in Sql Server 2005:
- USER Table: information about user and so on.
- COUNTRY Table : Holds list of whole countries on the world.
USER_COUNTRY Table: Which matches, which user has visited which county. It holds, UserID and CountryID. For example, USER_COUNTRY table looks like this:
ID -- UserID -- CountryID
- 1 -- 1 -- 34
- 2 -- 1 -- 5
- 3 -- 2 -- 17
- 4 -- 2 -- 12
- 5 -- 2 -- 21
- 6 -- 3 -- 19
My question is that: When a user is deleted in USER table, how can I make associated records in USER_COUNTRY table deleted directly. Maybe, by using Foreign Key Constaint?
© Stack Overflow or respective owner