-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_DDL_Commands.sql
89 lines (80 loc) · 1.69 KB
/
01_DDL_Commands.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- Banking Dataset - Columns:
-- Customers
-- Accounts
-- Transactions
-- Products
-- Branch
-- Employees
SELECT * FROM information_schema.TABLES WHERE table_schema='public';
-- CREATING TABLES:
CREATE TABLE Customers
(
Customer_ID VARCHAR(20),
First_Name VARCHAR(20),
Last_Name VARCHAR(20),
Phone_No BIGINT,
address VARCHAR(50),
DOB DATE,
Is_Active BOOLEAN
);
CREATE TABLE Accounts
(
Acc_No INT,
Acc_Type VARCHAR(20),
Cust_Id VARCHAR(20),
Balance FLOAT
);
CREATE TABLE Transactions
(
Trans_Id INT,
Trans_Type VARCHAR(20),
Trans_Date DATE,
Acc_No INT,
Amount FLOAT,
Status VARCHAR(20)
);
CREATE TABLE Products
(
Prod_Id VARCHAR(10),
Prod_Name VARCHAR(20),
Prod_Desc VARCHAR(200)
);
CREATE TABLE Branch
(
Branch_Name VARCHAR(20),
Branch_Code VARCHAR(20),
);
CREATE TABLE Employees
(
Emp_Id VARCHAR(20),
First_Name VARCHAR(20),
Last_Name VARCHAR(20),
Salary FLOAT,
Branch_Code VARCHAR(20)
);
SELECT * FROM Customers;
SELECT * FROM Accounts;
SELECT * FROM Transactions;
SELECT * FROM Products;
SELECT * FROM Branch;
SELECT * FROM Employees;
-- Renaming Column name:
ALTER TABLE Customer RENAME COLUMN Customer_Id TO cust_id;
-- Renaming Table name:
ALTER TABLE Customers RENAME TO Customer;
-- Altering Datatype:
ALTER TABLE Customers ALTER COLUMN Phone_No TYPE INT;
-- Adding a Column:
ALTER TABLE Customers ADD COLUMN Demo VARCHAR(20);
-- Removing a Column:
ALTER TABLE Customers DROP COLUMN Demo;
-- To remove Table:
DROP TABLE Customers;
DROP TABLE Accounts;
DROP TABLE Transactions,
DROP TABLE Products;
DROP TABLE Branch;
DROP TABLE Employees;
DROP TABLE IF EXISTS Demo;
-- REMOVE ALL THE DATA FROM THE TABLE:
TRUNCATE TABLE Customers;