Home Forums SQL Server 2005 SQL Server Newbies How to design 1:n relationships in Sql Server Management Studio? RE: How to design 1:n relationships in Sql Server Management Studio?

  • info (3/1/2009)


    Imagine I have two tables: Manager and Player. This is for a football team, where several players can play for one manager only and a manager manages several (11) players.

    When designing the relationship in Sql Server, at the time the popup window comes up with the properties for the relationship, does it matter which side the tables are?

    So in other words is there a difference in connecting the key from Player to Manager or from Manager to Player?

    And how do I specify the relationship as 1:n or is it automatically decided as 1:n or 1:1? In Access you can choose between 1:1 and 1:n due to the connector style (crows feet and all that), but not in Sql Server.

    Thanks

    It matters, but it's the structure that makes the difference. If you have a Manager, let's say the PK is the ManagerID, and you have a Player, who's PK is PlayerID (maybe not the best choices, I'm not arguing that, they're easy for references). In your tables, if neither has a field that represents the PK of the other, then you can't establish a relationship. But if the Player has a ManagerID field, then you can't ever have 1:n from the Player to the Manager. Think about it. Only a single Manager can possibly be associated with the player in that situation. But look at it from the other point of view. A manager can have any number of players with his ID in the associated field, making it 1:n.

    To make it go the other way for the player to the manager, the manager would have to have a field that associates to the player, but, that's going to make for very small football teams.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning