forked from Yashappin/Python_Content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQL-Commands.txt
More file actions
175 lines (151 loc) · 4.39 KB
/
MySQL-Commands.txt
File metadata and controls
175 lines (151 loc) · 4.39 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database empDB;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| empDB |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> use empDB;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> CREATE TABLE emp(empId INT PRIMARY KEY auto_increment, name VARCHAR(50), salary FLOAT(13,4));
Query OK, 0 rows affected (0.40 sec)
mysql> show tables;
+-----------------+
| Tables_in_empDB |
+-----------------+
| emp |
+-----------------+
1 row in set (0.00 sec)
mysql> INSERT INTO emp(name,salary) VALUES('Akram', 256000.50);
Query OK, 1 row affected (0.36 sec)
mysql> INSERT INTO emp(name,salary) VALUES('Amit', 200000.50);
Query OK, 1 row affected (0.09 sec)
mysql> INSERT INTO emp(name,salary) VALUES('Rajeev', 250000.50);
Query OK, 1 row affected (0.07 sec)
mysql> SELECT * FROM EMP;
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 1 | Akram | 256000.5000 |
| 2 | Amit | 200000.5000 |
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
3 rows in set (0.00 sec)
mysql> SELECT empId, name FROM EMP;
+-------+--------+
| empId | name |
+-------+--------+
| 1 | Akram |
| 2 | Amit |
| 3 | Rajeev |
+-------+--------+
3 rows in set (0.00 sec)
mysql> SELECT count(*) FROM EMP;
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE empId = 2;
+-------+------+-------------+
| empId | name | salary |
+-------+------+-------------+
| 2 | Amit | 200000.5000 |
+-------+------+-------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE empId = 2 OR empId = 3;
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 2 | Amit | 200000.5000 |
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE empId IN(2,3);
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 2 | Amit | 200000.5000 |
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE empId NOT IN(2,3);
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 1 | Akram | 256000.5000 |
+-------+--------+-------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE name='Akram';
+-------+--------+-------------+
| empid | name | salary |
+-------+--------+-------------+
| 1 | Akram | 256000.5000 |
+-------+--------+-------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE name LIKE '%r%';
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 1 | Akram | 256000.5000 |
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE name LIKE 'r%';
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE name LIKE '%m';
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 1 | Akram | 256000.5000 |
+-------+--------+-------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM EMP WHERE name LIKE '_a%';
+-------+--------+-------------+
| empId | name | salary |
+-------+--------+-------------+
| 3 | Rajeev | 250000.5000 |
+-------+--------+-------------+
1 row in set (0.00 sec)
mysql> SELECT count(*) FROM EMP WHERE name LIKE '_a%';
+----------+
| count(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT count(*) FROM EMP WHERE name LIKE '%r%';
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
mysql> UPDATE EMP SET salary = 24000 WHERE empId = 3;
1 row in set (0.00 sec)
mysql> DELETE FROM emp WHERE empId = 2;
1 row in set (0.00 sec)