My Code:
create table Products
(
ProductID int not null auto_increment primary key,
ProductName varchar(20),
Recommendedprice decimal(10,2),
Category varchar(10)
)
create table customers
(
CustomerID int not null auto_increment primary key,
FirstName varchar(50),
LastName varchar(50),
city varchar(50),
State char(2),
zip varchar(10)
)
create table sales
(
SalesID int not null auto_increment primary key,
ProductID int,
CustomerID int,
CONSTRAINT fk_PerProducts FOREIGN KEY (ProductId)
REFERENCES Products(ProductId),
CONSTRAINT fk_PerCustomers FOREIGN KEY (CustomerId)
REFERENCES customers(customerId),
SalesPrice decimal(10,2),
SalesDate date
)
I get null values in the table list.
You need to send the id of the foreigner key when you make an INSERT.
like this (paper_Author
work like your sales
table) :
CREATE TABLE Paper (`paperId` int, `title` varchar(7));
INSERT INTO Paper (`paperId`, `title`)
VALUES (1, 'hello'),(2, 'hola'),(3, 'bonjour');
CREATE TABLE Author (`authorId` int, `authorName` varchar(3));
INSERT INTO Author (`authorId`, `authorName`)
VALUES (1, 'me'),(2, 'moi');
CREATE TABLE Paper_Author (`paperId` int, `authorId` int);
INSERT INTO Paper_Author (`paperId`, `authorId`)
VALUES (1, 1),(1, 2),(2, 2);
and you use it like this : http://sqlfiddle.com/#!2/eb61f/2
other think you should read :