0% found this document useful (0 votes)
25 views1 page

SQL: Joining Customers, Orders, Products

The document outlines the creation of a database named 'SQL Questions' with three tables: Customers, Orders, and Products. It includes the structure of each table, primary keys, foreign key relationships, and sample data inserts for each table. The Customers table contains customer information, the Orders table records orders linked to customers, and the Products table lists product details.

Uploaded by

koulibalyhamam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

SQL: Joining Customers, Orders, Products

The document outlines the creation of a database named 'SQL Questions' with three tables: Customers, Orders, and Products. It includes the structure of each table, primary keys, foreign key relationships, and sample data inserts for each table. The Customers table contains customer information, the Orders table records orders linked to customers, and the Products table lists product details.

Uploaded by

koulibalyhamam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

create database [SQL Questions]

use [SQL Questions]

-- Create the Customers table


CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(50),
Country VARCHAR(50)
);

-- Insert data into Customers table


INSERT INTO Customers (CustomerID, CustomerName, Country)
VALUES
(1, 'Alice', 'USA'),
(2, 'Bob', 'UK'),
(3, 'Charlie', 'Canada'),
(4, 'David', 'USA'),
(5, 'Eve', 'Australia');

-- Create the Orders table


CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
ProductID INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);

-- Insert data into Orders table


INSERT INTO Orders (OrderID, CustomerID, OrderDate, ProductID)
VALUES
(101, 1, '2024-08-01', 1001),
(102, 1, '2024-08-03', 1002),
(103, 2, '2024-08-04', 1001),
(104, 3, '2024-08-05', 1003),
(105, 5, '2024-08-06', 1004);

-- Create the Products table


CREATE TABLE Products (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
Price DECIMAL(10, 2)
);

-- Insert data into Products table


INSERT INTO Products (ProductID, ProductName, Price)
VALUES
(1001, 'Laptop', 1000),
(1002, 'Smartphone', 700),
(1003, 'Tablet', 500),
(1004, 'Headphones', 200),
(1005, 'Smartwatch', 300);

You might also like