这是我第一次尝试创建具有多个表的这种性质的数据库。
项目:一家拍卖行,只需要展示他们的下一个拍卖目录
表布局:
- 每年将有 4-5 个新目录,每次新拍卖 1 个目录
- 每个目录将分为通用子类别,例如“家具”、“玻璃器皿”等...
- 每个子类别都将填充独特的地段
- 每个拍品都有唯一的拍品编号、标题、简要说明、照片、估价
我只是想弄清楚我最初的尝试;我的结构/术语是否正确?
我已经运行了一些将表连接在一起的查询,并且得到了我请求的数据。
在进行此操作之前,我只是希望有更多知识/经验的人让我放心,这会坚持下去。
对此的任何指针将不胜感激,或者一个简单的“代码将保留”:)
DROP TABLE IF EXISTS catalogues;
CREATE TABLE IF NOT EXISTS catalogues (
catalogueid INT(11) NOT NULL AUTO_INCREMENT,
active TINYINT (1) DEFAULT '0',
auctiondate VARCHAR(15) DEFAULT NULL,
datecreated TIMESTAMP DEFAULT '0000-00-00 00:00:00',
lastmodified TIMESTAMP DEFAULT now() ON UPDATE now(),
PRIMARY KEY (catalogueid),
KEY catalogue (auctiondate)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO catalogues (active, auctiondate, datecreated,
lastmodified) VALUES
(0, '01-Jan-13', null, null),
(1, '01-Feb-13', null, null);
DROP TABLE IF EXISTS categories;
CREATE TABLE IF NOT EXISTS categories (
categoryid INT(11) NOT NULL AUTO_INCREMENT,
category VARCHAR(20) DEFAULT NULL,
PRIMARY KEY (categoryid),
KEY category (category(5))
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO categories (category) VALUES
('Category 1'),
('Category 2'),
('Category 3'),
('Category 4');
DROP TABLE IF EXISTS lots;
CREATE TABLE IF NOT EXISTS lots (
lotid INT(11) NOT NULL AUTO_INCREMENT,
lotnumber INT(11) DEFAULT NULL,
title VARCHAR(128) DEFAULT NULL,
catalogueid INT(11) NOT NULL,
categoryid INT(11) NOT NULL,
estimatefrom INT(5) DEFAULT NULL,
estimateto INT(5) DEFAULT NULL,
photo VARCHAR(50) DEFAULT NULL,
datecreated TIMESTAMP DEFAULT '0000-00-00 00:00:00',
lastmodified TIMESTAMP DEFAULT now() ON UPDATE now(),
PRIMARY KEY (lotid),
KEY title (title(20)),
FOREIGN KEY (catalogueid) REFERENCES catalogues (catalogueid),
FOREIGN KEY (categoryid) REFERENCES categories (categoryid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;
INSERT INTO lots (lotnumber, title, catalogueid, categoryid,
estimatefrom, estimateto, photo, datecreated, lastmodified) VALUES
(1, 'Title 1', 1, 1, '1000', '1500', 'photo-1.jpg', null, null),
(5, 'Title 2', 1, 2, '500', '800', 'photo-2.jpg', null, null),
(10, 'Title 3', 2, 3, '80', '120', 'photo-3.jpg', null, null),
(15, 'Title 4', 2, 4, '1000', '1500', 'photo-4.jpg', null, null);
DROP TABLE IF EXISTS lotdescription;
CREATE TABLE IF NOT EXISTS lotdescription (
lotid INT(11) NOT NULL AUTO_INCREMENT,
description VARCHAR(500) DEFAULT NULL,
FULLTEXT KEY description_2 (description),
FOREIGN KEY (lotid) REFERENCES lots (lotid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO lotdescription (description) VALUES
('Lot Description 1'),
('Lot Description 2'),
('Lot Description 3'),
('Lot Description 4');