0% found this document useful (0 votes)
6 views

Advanced Database Concepts4a-Create Database Business

The document creates a database and tables for a business database including customers, products, orders, and order details tables. It then inserts sample records into each table.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Advanced Database Concepts4a-Create Database Business

The document creates a database and tables for a business database including customers, products, orders, and order details tables. It then inserts sample records into each table.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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', '[email protected]', '123-456-7890'),
('Jane', 'Kamara', '[email protected]', '987-654-3210'),
('Alice', 'Johnson', '[email protected]', '555-666-7777'),
('Bob', 'Brown', '[email protected]', '222-333-4444'),
('Charlie', 'Davis', '[email protected]', '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