sql server - relationship many to many -
i want create database relationship many many. have error
sql71516 :: referenced table '[dbo].[bookauthors]' contains no primary or candidate keys match referencing column list in foreign key. if referenced column computed column, should persisted. sql71516 :: referenced table '[dbo].[bookauthors]' contains no primary or candidate keys match referencing column list in foreign key. if referenced column computed column, should persisted.
how fix this?
create table [dbo].[bookauthors] ( [book] int not null, [author] int not null, primary key clustered ([book] asc,[author] asc) ); create table [dbo].[books] ( [id] int not null, [title] nvarchar (max) null, [price] money null, [category] int null, primary key clustered ([id] asc), foreign key ([id]) references [dbo].[bookauthors] ([book]) ); create table [dbo].[authors] ( [id] int not null, [name] nchar (10) not null, primary key clustered ([id]), foreign key ([id]) references [dbo].[bookauthors] ([author]) );
you crated in bookauthors composite primary key consists of 2 columns: book , author. when referencing it, need reference both columns. other solution make in bookauthors third column (identity maybe) primary key , reference one.
Comments
Post a Comment