0% found this document useful (0 votes)
59 views3 pages

SQL Create & Insert

The document creates tables for a store database including tables for customers, staff, item types, items, sales transactions and transaction details. It then inserts sample data into each table.

Uploaded by

Arif Jerat
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
59 views3 pages

SQL Create & Insert

The document creates tables for a store database including tables for customers, staff, item types, items, sales transactions and transaction details. It then inserts sample data into each table.

Uploaded by

Arif Jerat
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

CREATE DATABASE CourseNet_Store

GO
USE CourseNet_Store

-- Create MsCustomer
CREATE TABLE MsCustomer(
CustomerId CHAR(5) PRIMARY KEY,
CustomerName VARCHAR(50),
CustomerGender VARCHAR(10),
CustomerPhone VARCHAR(13),
CustomerAddress VARCHAR(100),
CONSTRAINT cekIDCust CHECK(CustomerId LIKE 'CU[0-9][0-9][0-9]')
)

-- Create MsStaff
CREATE TABLE MsStaff(
StaffId CHAR(5) PRIMARY KEY,
StaffName VARCHAR(50),
StaffGender VARCHAR(10),
StaffPhone VARCHAR(13),
StaffAddress VARCHAR(100),
StaffSalary NUMERIC(11,2),
StaffPosition VARCHAR(20),
CONSTRAINT cekIDStaff CHECK(StaffId LIKE 'SF[0-9][0-9][0-9]')
)

-- Create MsItemType
CREATE TABLE MsItemType(
ItemTypeId CHAR(5) PRIMARY KEY,
ItemTypeName VARCHAR(50),
CONSTRAINT cekIDItemType CHECK(ItemTypeId LIKE 'IT[0-9][0-9][0-9]')
)

-- Create MsItem
CREATE TABLE MsItem(
ItemId CHAR(5) PRIMARY KEY,
ItemTypeId CHAR(5) REFERENCES MsItemType ON UPDATE CASCADE ON DELETE CASCADE,
ItemName VARCHAR(50),
Price NUMERIC(11,2),
Quantity NUMERIC(11,2),
CONSTRAINT cekIDItem CHECK(ItemId LIKE 'IM[0-9][0-9][0-9]')
)

-- Create HeaderSellTransaction
CREATE TABLE HeaderSellTransaction(
TransactionId CHAR(5) PRIMARY KEY,
CustomerId CHAR(5) REFERENCES MsCustomer ON UPDATE CASCADE ON DELETE CASCADE,
StaffId CHAR(5) REFERENCES MsStaff ON UPDATE CASCADE ON DELETE CASCADE,
TransactionDate DATE,
PaymentType VARCHAR(20),
CONSTRAINT cekIDTrans CHECK(TransactionId LIKE 'TR[0-9][0-9][0-9]')
)

-- Create DetailSellTransaction
CREATE TABLE DetailSellTransaction(
TransactionId CHAR(5) REFERENCES HeaderSellTransaction ON UPDATE CASCADE ON
DELETE CASCADE,
ItemId CHAR(5) REFERENCES MsItem ON UPDATE CASCADE ON DELETE CASCADE,
SellQuantity NUMERIC(11,2),
PRIMARY KEY(TransactionId, ItemId)
)

-- Insert Data
INSERT INTO MsCustomer VALUES
('CU001', 'Kevin Axellino Triantio', 'Male', '081267381930', 'Jelambar Street no
17'),
('CU002', 'Kerin Augustin', 'Female', '081372116372', 'Ancol Barat Street no 190'),
('CU003', 'Fernando Lioexander', 'Male', '087824153627', 'Palmerah Street no 20'),
('CU004', 'Naufal Hafiz', 'Male', '081127173829', 'Duri Kepa Street no 9'),
('CU005', 'Arya Thomas', 'Male', '081811992617', 'Anggrek Street no 12')

INSERT INTO MsStaff VALUES


('SF001', 'Venky Eduardo', 'Male', '081927183617', 'Budi Raya Street no 100',
15000000, 'Manager'),
('SF002', 'Poppy Hwangsa Iswara', 'Female', '085714263367', 'Budi Raya Street no
11', 10000000, 'Supervisor'),
('SF003', 'Louis Rudy Valen', 'Male', '089915276278', 'Serpong Raya Street no 109',
6000000, 'Cashier'),
('SF004', 'Andika Leonardo', 'Male', '081189227888', 'BSD Raya Street no 1',
6500000, 'Cashier'),
('SF005', 'Nathaniel Putera', 'Male', '087715551782', 'Ciledug Street no 233',
7300000, 'Cashier'),
('SF006', 'Olive Kusuma', 'Female', '083287345383', 'Serpong Raya Street no 117',
6700000, 'Cashier')

INSERT INTO MsItemType VALUES


('IT001', 'Electronic'),
('IT002', 'Sport'),
('IT003', 'Furniture'),
('IT004', 'Fashion'),
('IT005', 'Health')

INSERT INTO MsItem VALUES


('IM001', 'IT001','Camera', 9000000, 10),
('IM002', 'IT001','Television', 3300000, 19),
('IM003', 'IT001','Handphone', 5100000, 9),
('IM004', 'IT001','Laptop', 10050000, 20),
('IM005', 'IT001','Rice cooker', 950000, 17),
('IM006', 'IT001','Lamp', 95000, 90),
('IM007', 'IT001','Modem', 420000, 77),
('IM008', 'IT001','Harddisk', 7900000, 16),
('IM009', 'IT001','Mouse', 210000, 29),
('IM010', 'IT001','Keyboard', 170000, 41),
('IM011', 'IT002','Racket', 630000, 22),
('IM012', 'IT002','Volleyball', 420000, 28),
('IM013', 'IT002','Golf stick', 1900000, 12),
('IM014', 'IT002','Basketball', 920000, 14),
('IM015', 'IT002','Bicycle', 2300000, 25),
('IM016', 'IT002','Diving', 4400000, 12),
('IM017', 'IT003','Bed', 2100000, 32),
('IM018', 'IT003','Stove', 320000, 20),
('IM019', 'IT003','Wardrobe', 760000, 17),
('IM020', 'IT004','Blazer', 420000, 41),
('IM021', 'IT004','Shirt', 320000, 64),
('IM022', 'IT004','Pants', 580000, 52),
('IM023', 'IT004','Hat', 210000, 58),
('IM024', 'IT005','Vitamin', 290000, 99),
('IM025', 'IT005','Sunblock', 125000, 32),
('IM026', 'IT005','Body lotion', 320000, 48)

INSERT INTO HeaderSellTransaction VALUES


('TR001', 'CU001', 'SF004', '2017/12/20', 'Credit'),
('TR002', 'CU002', 'SF005', '2017/12/20', 'Credit'),
('TR003', 'CU003', 'SF003', '2017/12/20', 'Cash'),
('TR004', 'CU004', 'SF005', '2017/12/20', 'Debit'),
('TR005', 'CU005', 'SF003', '2017/12/21', 'Debit'),
('TR006', 'CU001', 'SF005', '2017/12/21', 'Credit'),
('TR007', 'CU002', 'SF001', '2017/12/22', 'Cash'),
('TR008', 'CU003', 'SF002', '2017/12/22', 'Credit'),
('TR009', 'CU005', 'SF004', '2017/12/22', 'Debit')

INSERT INTO DetailSellTransaction VALUES


('TR001', 'IM001', 1),
('TR001', 'IM005', 2),
('TR002', 'IM010', 2),
('TR002', 'IM015', 1),
('TR003', 'IM025', 3),
('TR003', 'IM009', 1),
('TR004', 'IM001', 1),
('TR004', 'IM006', 3),
('TR004', 'IM015', 3),
('TR004', 'IM016', 1),
('TR005', 'IM016', 2),
('TR006', 'IM006', 4),
('TR006', 'IM015', 6),
('TR007', 'IM002', 2),
('TR007', 'IM005', 2),
('TR008', 'IM002', 3),
('TR008', 'IM006', 1),
('TR009', 'IM005', 1),
('TR009', 'IM006', 2)

You might also like