Advanced Database Concepts4a-Create Database Business

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

create database Business

go

use Business
go

CREATE TABLE Customers (


CustomerID INT Identity (1,1) PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100),
PhoneNumber VARCHAR(15)
)

CREATE TABLE Products (


ProductID INT Identity (1,1) PRIMARY KEY,
ProductName VARCHAR(100),
ProductDescription TEXT,
Price DECIMAL(10, 2)
)

CREATE TABLE Orders (


OrderID INT Identity (1,1) PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
TotalAmount DECIMAL(10, 2),
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
)

CREATE TABLE OrderDetails (


OrderDetailID INT Identity (1,1) PRIMARY KEY,
OrderID INT,
ProductID INT,
Quantity INT,
UnitPrice DECIMAL(10, 2),
FOREIGN KEY (OrderID) REFERENCES Orders(OrderID),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
)

-- INSERTING RECORDS INTO THE TABLES --

-- Insert Customers
INSERT INTO Customers (FirstName, LastName, Email, PhoneNumber) VALUES
('Nbaba', 'Kallon', 'john.doe@example.com', '123-456-7890'),
('Jane', 'Kamara', 'jane.smith@example.com', '987-654-3210'),
('Alice', 'Johnson', 'alice.johnson@example.com', '555-666-7777'),
('Bob', 'Brown', 'bob.brown@example.com', '222-333-4444'),
('Charlie', 'Davis', 'charlie.davis@example.com', '888-999-0000')

-- Insert Products
INSERT INTO Products (ProductName, ProductDescription, Price) VALUES
('Laptop', 'High performance laptop', 999.99),
('Smartphone', 'Latest model smartphone', 799.99),
('Tablet', '10 inch screen tablet', 499.99),
('Headphones', 'Noise cancelling headphones', 199.99),
('Smartwatch', 'Wearable smart device', 299.99)
-- Insert Orders
INSERT INTO Orders (CustomerID, OrderDate, TotalAmount) VALUES
(1, '2023-06-01', 999.99),
(2, '2023-06-02', 1799.98),
(3, '2023-06-03', 499.99),
(4, '2023-06-04', 399.98),
(5, '2023-06-05', 299.99)

-- Insert OrderDetails
INSERT INTO OrderDetails (OrderID, ProductID, Quantity, UnitPrice) VALUES
(1, 1, 1, 999.99),
(2, 2, 1, 799.99),
(2, 3, 1, 999.99),
(3, 3, 1, 499.99),
(4, 4, 2, 199.99),
(5, 5, 1, 299.99)

select * from Customers


select * from Products
select * from Orders
select * from OrderDetails

You might also like