Home Forums SQL Server 2012 SQL 2012 - General Performance with Referencing or not referencing, index or with index? RE: Performance with Referencing or not referencing, index or with index?

  • Detail.Id column is already clustered PK index, Do you want me to add another index non clustered (Detail.Id, Detail.MasterId)?

    CREATE TABLE [dbo].[MasterT](

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

    [Name] [varchar](50) NOT NULL,

    CONSTRAINT [PK_MasterT] PRIMARY KEY CLUSTERED

    (

    [Id] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    CREATE TABLE [dbo].[DetailT](

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

    [MasterId] [int] NOT NULL,

    [Amount] [int] NOT NULL,

    [Dt] [datetime] NOT NULL,

    CONSTRAINT [PK_DetailT] PRIMARY KEY CLUSTERED

    (

    [Id] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[DetailT] ADD CONSTRAINT [DF_DetailT_Dt] DEFAULT (getdate()) FOR [Dt]

    GO

    ALTER TABLE [dbo].[DetailT] WITH CHECK ADD CONSTRAINT [FK_DetailT_MasterT] FOREIGN KEY([MasterId])

    REFERENCES [dbo].[MasterT] ([Id])

    GO

    ALTER TABLE [dbo].[DetailT] CHECK CONSTRAINT [FK_DetailT_MasterT]

    GO

    Let me clear on this. I have several questions related to this I need to know this first.

    Regards,

    Shamshad