-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLQuery2.sql
112 lines (97 loc) · 2.71 KB
/
SQLQuery2.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- Create the database
CREATE DATABASE cricket;
-- Switch to the 'cricket' database
USE cricket;
-- Create the table
CREATE TABLE new_tables (
YEAR INT,
Winner_team VARCHAR(100)
);
-- Select from the table (will return empty initially)
SELECT * FROM new_tables;
-- Insert data into the table
INSERT INTO new_tables (YEAR, Winner_team)
VALUES
(2008, 'Rajasthan'),
(2009, 'Deccan Chargers'),
(2010, 'Chennai Super Kings'),
(2011, 'Kolkata Knight Riders'),
(2013, 'Mumbai Indians'),
(2014, 'Kolkata Riders');
-- Display data in the table
SELECT * FROM new_tables;
-- Alter the table to add new columns
ALTER TABLE new_tables
ADD
Runner_up VARCHAR(100),
Final_Match_venue VARCHAR(100),
Captain VARCHAR(100),
Player_of_the_series VARCHAR(100),
Man_of_the_match VARCHAR(100);
-- Update the table
UPDATE new_tables
SET
Runner_up = 'Chennai Super Kings',
Final_Match_venue = 'Mumbai',
Captain = 'MS Dhoni',
Player_of_the_series = 'Sachin Tendulkar',
Man_of_the_match = 'Rohit Sharma'
WHERE YEAR = 2010; -- Specify a condition to update the correct row
-- Update the table
UPDATE new_tables
SET
Runner_up = 'Rajasthan',
Final_Match_venue = 'Delhi',
Captain = 'Raina',
Player_of_the_series = 'kumblai',
Man_of_the_match = 'sardu'
WHERE YEAR = 2008;
-- Update the table
UPDATE new_tables
SET
Runner_up = 'mumbai',
Final_Match_venue = 'Mumbai',
Captain = 'MS Dhoni',
Player_of_the_series = 'Sachin Tendulkar',
Man_of_the_match = 'Rohit Sharma'
WHERE YEAR = 2013;
-- Update the table
UPDATE new_tables
SET
Runner_up = 'Kolkata night',
Final_Match_venue = 'Gujrat',
Captain = 'Nehra',
Player_of_the_series = 'Hook',
Man_of_the_match = 'Piterson'
WHERE YEAR = 2011;
-- Display the updated table
SELECT * FROM new_tables;
UPDATE new_tables
SET
Runner_up = 'Deccan chargers',
Final_Match_venue = 'Bangalore',
Captain = 'Nehra',
Player_of_the_series = 'Hook',
Man_of_the_match = 'Piterson'
WHERE YEAR = 2009;
-- Display the updated table
SELECT * FROM new_tables;
Update new_tables
Set Runner_Up = 'Gujarat Titans',
Final_Match_Venue = 'Ahmedabad',
Captain = 'MS Dhoni',
Player_of_the_Series = 'Shubman Gill',
Man_of_the_Match = 'Devon Conway'
Where YEAR = 2014
SELECT * FROM new_tables;
--Deleting the Column from the table (Drop)
Alter Table new_tables
Drop Column YEAR
Select * from new_tables
--Deleting the Row from the table (Delete)
Delete from new_tables
Where Winner_team = 'Chennai Super Kings'
Select * from new_tables
-- Deleting the entire table
Truncate table new_tables
Select * from new_tables