4
Session 1 ( --CREATE DATABASE LotteMart --CREATE TABLE MasterGoods --( --GoodsCode VARCHAR (15) NOT NULL, --GoodsName TEXT NOT NULL, --GoodsQuantity INT NOT NULL, --GoodsPrice FLOAT --) CREATE TABLE PaymentType ( PaymentID INT NOT NULL,--The primary Key for PaymentType Table PaymentName VARCHAR (100) NOT NULL, PaymentBank VARCHAR (100) NULL, ) CREATE TABLE Sales ( SalesCode CHAR (24) NOT NULL,--Primary key for the Sales Tables PaymentID INT NOT NULL --Foreign key(the primary key that is used for another tables) SalesAmount FLOAT NOT NULL SalesTotalQty INT NOT NULL, ) CHAR (10) VARCHAR (10) TEXT BIT TINYINT INT 1500 FLOAT 1500.50 INT FLOAT DATETIME yyyy.mm.dd H:i:S DATE YEAR --DROP DATABASE LotteMart

Create Database Lottemart

Embed Size (px)

DESCRIPTION

a brief explanation about how to create a database that is simple. This was taken from the receipt from Lottemart.

Citation preview

Page 1: Create Database Lottemart

Session 1 ( --CREATE DATABASE LotteMart

--CREATE TABLE MasterGoods--(

--GoodsCode VARCHAR (15) NOT NULL,--GoodsName TEXT NOT NULL,--GoodsQuantity INT NOT NULL,--GoodsPrice FLOAT

--)

CREATE TABLE PaymentType(

PaymentID INT NOT NULL,--The primary Key for PaymentType TablePaymentName VARCHAR (100) NOT NULL,PaymentBank VARCHAR (100) NULL,

)

CREATE TABLE Sales(

SalesCode CHAR (24) NOT NULL,--Primary key for the Sales Tables PaymentID INT NOT NULL --Foreign key(the primary key that is used for

another tables)SalesAmount FLOAT NOT NULLSalesTotalQty INT NOT NULL,

)

CHAR (10)VARCHAR (10)TEXT

BITTINYINTINT 1500FLOAT 1500.50

INTFLOAT

DATETIME yyyy.mm.dd H:i:SDATEYEAR

--DROP DATABASE LotteMart

Page 2: Create Database Lottemart

Session 2

Composite Primary Key is the combination of two or more primary keys into one big primary key because only one column can represent the primary key.

Types of Table :

1. Master Table: provide detailed informations (products, customers)2. Transaction Table: has dimension (time) and has transaction inside.

Primary Key: the unique code that represents its rows

Foreign Key: the primary key that is used in another table as the addition information

--Database CreationCREATE DATABASE LotteMart

CREATE TABLE MasterGoods(

GoodsCode CHAR(15) NOT NULL,GoodsName TEXT NOT NULL,GoodsQuantity INT NOT NULL,GoodsPrice FLOAT

)

CREATE TABLE PaymentType(

PaymentID INT PRIMARY KEY NOT NULL,PaymentName VARCHAR(100) NOT NULL,PaymentBank VARCHAR(100) NULL

)

CREATE TABLE Sales(

SalesCode CHAR(24) NOT NULL,PaymentID INT NOT NULL,SalesAmount FLOAT NOT NULL,SalesTotalQty INT NOT NULL

)

CREATE TABLE Staff(

StaffID CHAR(5) PRIMARY KEY NOT NULL,StaffName VARCHAR(100)NOT NULL,StaffPhone VARCHAR(20) NULL,StaffAddress TEXT NULL

)

DROP TABLE Staff --to Delete the Table

--DROP TABLE Sales

Page 3: Create Database Lottemart

--DROP DATABASE LotteMart

ALTER TABLE SalesADD StaffID CHAR(5)NOT NULL REFERENCES Staff(StaffID)

ALTER TABLE SalesDROP COLUMN SalesAmount, SalesTotalQty

ALTER TABLE SalesADD SalesAmount FLOAT NOT NULL,

SalesTotalQty INT NOT NULL, SalesDate DATETIME NOT NULL

ALTER TABLE MasterGoodsALTER COLUMN GoodsName VARCHAR(100)

INSERT INTO StaffVALUES(

'00001','Rooky Balboa','0123456789','Straight Street 5'

)

INSERT INTO MasterGoods(

GoodsCode,GoodsName,GoodsQuantity

)VALUES(

'000000000000001','Item1',10

)

SELECT * FROM Staff --select which one to be displayed

SELECT GoodsCode, GoodsName FROM MasterGoodsWHERE GoodsQuantity = 10