Question

I have the following tables

books(
  bkid varchar(255),
  bkname varchar(255),
  bkauth varchar(255),
  bkpub varchar(255),
  bkedn int(10)
)

members(
  memid varchar(255),
  memname varchar(255),
  memaddr varchar(255),
  memcon varchar(255),
  mememail varchar(255)
)

bkid and memid are primary keys.

Now I am trying to make a composite primary key (bkid and memid) taking them as foreign keys from the tables books and members, the syntax is giving me some errors and I am not able to create the new table.

create table issuebooks(
  bkid varchar(255),
  memid varchar(255),
  issuestatus varchar(255),
  references foreign key bkid(books),
  references foreign key memid(members),
  primary key (bkid,memid)
);
Was it helpful?

Solution

Your create table statement is incorrect. This will work (tested on SQLFiddle)

create table issuebooks(
  bkid varchar(255) references bkid(books),
  memid varchar(255) references memid(members),
  issuestatus varchar(255),
  primary key (bkid,memid)
);

Advice... use integer id columns instead of VARCHAR(255) if you can... you won't regret it. And make those columns NOT NULL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top