Referential Integrity and Optimize

  • Hi

    I have these tables:

    CREATE TABLE [dbo].[Product](

    [ProductID] [int] IDENTITY(1,1) NOT NULL,

    [Code] [nvarchar](max) NOT NULL,

    [Qty] [int] NULL

    )

    AND

    CREATE TABLE [dbo].[Location](

    [LocationID] [int] IDENTITY(1,1) NOT NULL,

    [Code] [nvarchar](max) NOT NULL

    )

    How do I enforce referential integrity and optimize data retrieval as well as storage?

  • First fix your data types.

    Second, how do those tables relate to one another?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Create a foreign key between the columns that map between the two tables. Here's the documentation on that.

    "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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply