Reputation:
I'm only just starting out in SQL land and am trying to figure out what I am doing wrong with one of my tables. I have as followed
CREATE TABLE Winemaker (
Winemaker_id varchar (20) NOT NULL,
Winemaker_name varchar (20) NOT NULL,
key (Winemaker_Id));
CREATE TABLE Wine (
Wine_Id varchar (20) NOT NULL,
Wine_name varchar (20) NOT NULL,
Winemaker_Id varchar (4) NOT NULL,
Wine_vintage varchar (8) NOT NULL,
Wine_price varchar (8) NOT NULL
Primary key (Wine_Id)
Foreign key (Winemaker_Id) REFERENCES Winemaker(Id));
I am not quite sure what I've done wrong. If anyone could help that would be great, thanks!
Upvotes: 0
Views: 38
Reputation: 1270201
You have several issues, mostly around the definition of the foreign key reference. Try this:
CREATE TABLE Winemaker (
Winemaker_id varchar(20) NOT NULL,
Winemaker_name varchar(20) NOT NULL,
primary key (Winemaker_Id)
);
CREATE TABLE Wine (
Wine_Id varchar(20) NOT NULL,
Wine_name varchar(20) NOT NULL,
Winemaker_Id varchar(20) NOT NULL,
Wine_vintage varchar(8) NOT NULL,
Wine_price varchar (8) NOT NULL,
Primary key (Wine_Id),
Foreign key (Winemaker_Id) REFERENCES Winemaker(Winemaker_id)
);
SQL Fiddle is here.
Notes:
Winemaker
to have a foreign key reference to it.varchar
and (
are allowed, but they look awkward.Upvotes: 1