November 19, 2015 at 11:26 am
Hi,
Below my sample table schema,
Create table Company (CompanyId int primary key identity(1,1),CompanyName varchar(100));
Create table Messages(MessageID int primary key identity(1,1),MessageName varchar(100));
Create table Company_Messages(...........)
I need to create relational table (Company_Messages) table based on company and Messages. The condition here is companyId and MessageID pair should not be repeated in the
Company_Messages table. I can create this with companyId,MessageID as primary key. But how do i enforce the referential integrity here. CompId and Message ID should refrence their primaty key table.
how do i design table for this scenario. Any suggestion please
November 19, 2015 at 11:30 am
Something like this? Or I misunderstood the question?
CREATE TABLE Company_Messages(
CompanyId INT,
MessageID INT,
CONSTRAINT PK_Company_Messages PRIMARY KEY (CompanyId, MessageId),
CONSTRAINT FK_Company_Messages_Company FOREIGN KEY (CompanyId) REFERENCES Company(CompanyId),
CONSTRAINT FK_Company_Messages_Messages FOREIGN KEY (MessageId) REFERENCES Messages(MessageId));
November 19, 2015 at 11:40 am
Great, i am looking for this only. i had this in my mind but didn't know i can create like this.
Thanks Luiz for confirming. appreciated.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply