Hi, all,
I have a composite table called TicketAuthors that has four columns. Three of those are set to primary key. I have found that you can't have a NULL value with a composite table with multiple primary keys.
The issue I am having is that I am using a stored procedure to check to see if the name exists, if it doesn't, then to add the name.
Only problem is, I am getting the error in the attached screen shot.
I have found that the table is removing the identity specification for two of the three primary key columns.
I am not sure what to do about this as this is the first time I am working with a composite primary key.
I have been searching for hours for a resolution and haven't found one yet.
Stored Procedure:
Table setup:Code:ALTER PROCEDURE dbo.CheckTicketAuthorExists(@User VARCHAR(250)) AS BEGIN IF (SELECT COUNT(*) FROM TicketAuthors WHERE TicketAuthors = @User) = 0 BEGIN INSERT INTO TicketAuthors VALUES(@User) END END
All the three public key columns need to have the same value. Please advise as to your thoughts on how to get this working.Code:CREATE TABLE [dbo].[TicketAuthors]( [CreatedByID_PK] [int] NOT NULL, [LastModifiedByID_PK] [int] NOT NULL, [BeingViewedByID_PK] [int] IDENTITY(1,1) NOT NULL, [TicketAuthors] [varchar](250) NOT NULL, CONSTRAINT [PK_TicketAuthors] PRIMARY KEY CLUSTERED ( [CreatedByID_PK] ASC, [LastModifiedByID_PK] ASC, [BeingViewedByID_PK] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY]




Reply With Quote