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

DBMS sql code

The document provides SQL commands for creating and managing a coffee store database, including creating tables for products, customers, and orders. It also includes examples of inserting data, querying specific information, and manipulating tables. Additionally, it contains various SQL queries to retrieve data based on specific conditions related to customers and products.

Uploaded by

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

DBMS sql code

The document provides SQL commands for creating and managing a coffee store database, including creating tables for products, customers, and orders. It also includes examples of inserting data, querying specific information, and manipulating tables. Additionally, it contains various SQL queries to retrieve data based on specific conditions related to customers and products.

Uploaded by

Najmul huda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DBMS SQL step and how to run the code

Create Table

Question Code
CREATE coffee_store
DATABASE
Create new product CREATE TABLE products ( Id INT AUTO_INCREMENT PRIMARY
table KEY, name VARCHAR(30), Price DECIMAL(3,2) );
Create table for CREATE TABLE customers( id INT AUTO_INCREMENT PRIMARY
customers KEY, first_name VARCHAR(30), last_name VARCHAR(30), gender
ENUM('M','F'), phone_number VARCHAR(11) );
Create table for order CREATE TABLE orders( Id INT AUTO_INCREMENT PRIMARY KEY,
Product_id INT, Customer_id INT, Order_time DATETIME, FOREIGN
KEY(product_id)REFERENCES products(id), FOREIGN
KEY(customer_id)REFERENCES customers(id) );
Add table SELECT*FROM products;
ALTER TABLE products ADD COLUMN coffee_origin VARCHAR(30);
Delete table ALTER TABLE products DROP COLUMN coffee_origin;
CREATE DATABASE example; USE example; CREATE TABLE test( Id
INT AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(30), Age
INT ); SELECT*FROM test ; SHOW tables; TRUNCATE TABLE test;
Add product, price, INSERT INTO products(name,price,coffee_origin) VALUES
origin ('Espresso',2.50,'Brazil');
INSERT INTO products(name,price,coffee_origin)
VALUES('Macchiato',3.00,'Brazil'),('Cappuccino',3.50,'Costa Rica');
INSERT INTO products(name,price,coffee_origin)
VALUES('LATTE',3.50,'INDONESIA'),('AMERICANO',3.00,'BRAZIL'),
('FLAT WHITE',3.50,'INDONESIA'),('FILTER',3.00,'INDIA');
Answer insert into products(name, price, coffee_origin)
values('Espresso','2.50','Brazil'),('Macchiato','3.00','Brazil'),
('Cappuccino','3.50','Costa
Rica'),('Latte','3.50','Indonesia'),('Americano','3.00','Brazil'),('Flat
White','3.50','Indonesia'),('Filter','3.00','India');

After Create Table (Q and A)


1. From the customers table, select the SELECT first_name, phone_number FROM
first name and phone number of all the customers
females WHERE gender = 'F' AND last_name = 'Bluth';
who have a last name of Bluth.
2. From the products table, select the SELECT * FROM products
name for all products that have a price WHERE price > 3.00 AND coffee_origin = 'Sri
greater than 3.00 or a coffee origin of Sri Lanka';
Lanka.
3. How many male customers don't have a SELECT * FROM customers
phone number entered into the customers WHERE gender = 'M' AND phone_number is null;
table?
After Import File (Q and A)
SQL for list of all customers from table SELECT * FROMcustomers;
named customers.
How many customers are in customers SELECT count(*) FROM customers;
table
SQL for customer last name and phone SELECT last_name, phone_number FROM
number from customers table customers;
SQL for customer last name and phone SELECT last_name, phone_number FROM
number off all the females from customers
customers table WHERE gender = 'F';
SQL for customer last name and phone SELECT last_name, phone_number FROM
number of all the females who have a customers WHERE gender = 'F' and last_name =
last name Bluth in customers table 'Bluth';
How much coffee of origin Colombia SELECT * FROM products
from the products table? WHERE coffee_origin = 'Colombia';
How many coffee of origin Brazil from SELECT * FROM products
the products table? WHERE coffee_origin = 'Brazil';
How much coffee is 3.00 from the SELECT * FROM products
products table? WHERE price = 3.00;
How much coffee is 3.00 and origin is SELECT * FROM products
Brazil from the products table? WHERE price = 3.00
AND coffee_origin = 'Brazil';
How much coffee is greater than 3.00 SELECT * FROM products
from the products table? WHERE price > 3.00;
How much coffee is or greater than 3.00 SELECT * FROM products
from the products table? WHERE price >= 3.00;
How many customers do not have a SELECT * FROM customers
phone number? WHERE phone_number IS NULL;

You might also like