logo

Creating Database and Tables in TufftoysDB

   

Added on  2023-03-17

10 Pages1652 Words27 Views
Script
Drop database if exists TufftoysDB;
create database TufftoysDB;
Use TufftoysDB;
/* Create Database */
DROP TABLE IF EXISTS Customer;
CREATE TABLE Customer (
customerNumber int not null,
customerName varchar(40) NOT NULL,
phone varchar(20) NOT NULL,
email varchar(30) NOT NULL,
address varchar(50) NOT NULL,
balance double NOT NULL,
creditLimit int NOT NULL,
Primary Key (customerNumber)
);
DROP TABLE IF EXISTS Item;
CREATE TABLE Item (

itemCode int not null,
description varchar(40) NOT NULL,
category varchar(20) NOT NULL,
suggestedRetail varchar(30) NOT NULL,
cost varchar(50) NOT NULL,
overseas double NOT NULL,
QOH int NOT NULL,
minStockLevel int NOT NULL,
Primary Key (itemCode)
);
DROP TABLE IF EXISTS DeliveryMethod;
CREATE TABLE DeliveryMethod (
deliveryMethod varchar(20) not null,
charge double NOT NULL,
Primary Key (deliveryMethod)
);
DROP TABLE IF EXISTS SalesRep;
CREATE TABLE SalesRep (
salesRepID int not null,
salesRepName varchar(40) NOT NULL,
address varchar(50) NOT NULL,

mobile varchar(20) NOT NULL,
email varchar(30) NOT NULL,
hiredDate datetime NOT NULL,
agreedSalary double NOT NULL,
commissionRate int NOT NULL,
Primary Key (salesRepID)
);
DROP TABLE IF EXISTS `Order`;
CREATE TABLE `Order` (
orderNumber int not null,
salesRepID int NOT NULL,
orderDate datetime NOT NULL,
requiredDate datetime NOT NULL,
customerNumber int not null,
deliveryMethod varchar(20) not null,
Primary Key (orderNumber),
Constraint fk_customer foreign key (customerNumber) references customer (customerNumber),
Constraint fk_delMethod foreign key (deliveryMethod) references DeliveryMethod (deliveryMethod)
);
DROP TABLE IF EXISTS OrderItems;
CREATE TABLE OrderItems (

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
June 3 ICT 701 Relational Database Systems.
|6
|459
|41

Database Design and SQL
|29
|3169
|92

Database System for Desklib
|23
|3618
|214

Database Transaction: Case Study of Loan Payment
|12
|3403
|304

Business Information Systems Solved Assignment
|15
|1095
|122

ER Diagram, SQL Queries and Database Security for Desklib
|15
|1974
|437