码迷,mamicode.com
首页 > 数据库 > 详细

MySQL Study (MySQL从入门到精通)

时间:2014-10-16 19:38:22      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   sp   数据   on   ad   ef   

 创建一个简单的书籍出版跟踪数据库(UI工具 Navicat for MySQL) 

 


CREATE DATABASE publication_db;
USE publication_db;

CREATE TABLE poet(poet_code INT NOT NULL,first_name VARCHAR(30),surname VARCHAR(40),address VARCHAR(100),postcode VARCHAR(20),
telephone_number VARCHAR(30),PRIMARY KEY(poet_code));

CREATE TABLE poem(poem_Code INT NOT NULL,title VARCHAR(50),content TEXT,poet_Code INT NOT NULL,PRIMARY KEY(poem_Code),
INDEX(poet_Code),FOREIGN KEY(poet_Code) REFERENCES poet(poet_Code));

CREATE TABLE publication(publication_code INT NOT NULL,title VARCHAR(100),price MEDIUMINT UNSIGNED,PRIMARY KEY(publication_code));

CREATE TABLE poem_publication(poem_code INT NOT NULL,publication_code INT NOT NULL,PRIMARY KEY(poem_code,publication_code),
FOREIGN KEY(poem_code) REFERENCES poem(poem_code),FOREIGN KEY(publication_code) REFERENCES publication(publication_code));

CREATE TABLE sales_publication(sales_code INT NOT NULL,publication_code INT NOT NULL,PRIMARY KEY(sales_code,publication_code));

CREATE TABLE customer(customer_code INT NOT NULL,first_name VARCHAR(30),surname VARCHAR(30),address VARCHAR(100),postcode VARCHAR(20),
telephone_number VARCHAR(30),PRIMARY KEY(customer_code));

CREATE TABLE sale(sale_code INT NOT NULL,sale_date DATE,amount INT UNSIGNED,customer_code INT NOT NULL,PRIMARY KEY(sale_code),
INDEX(customer_code),FOREIGN KEY(customer_code) REFERENCES customer(customer_code));

 

MySQL Study (MySQL从入门到精通)

标签:io   os   ar   for   sp   数据   on   ad   ef   

原文地址:http://www.cnblogs.com/little-fresh/p/4029144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!