7 9 1st July 2024 Session 3

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

Enter password: ***********

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 9
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;


+-----------------------+
| Database |
+-----------------------+
| california_collisions |
| classicmodels |
| demonstration |
| excelr |
| experiment |
| information_schema |
| kunal |
| mmm |
| mysql |
| new excelr batch 10 |
| new excelr batch 11 |
| new excelr batch 12 |
| new excelr batch 13 |
| new excelr batch 14 |
| new excelr batch 15 |
| new excelr batch 16 |
| new excelr batch 17 |
| new excelr batch 18 |
| new excelr batch 3 |
| new excelr batch 5 |
| new excelr batch 6 |
| new excelr batch 7 |
| new excelr batch 8 |
| new excelr batch 9 |
| new_excelr_batch_2 |
| p |
| p_leetcode |
| parrot zoo |
| performance_schema |
| pratice |
| project1 |
| sakila |
| student_excelr |
| students |
| sys |
| test |
| timepass |
| tt |
| world |
| xyz |
+-----------------------+
40 rows in set (0.03 sec)
mysql> use `new excelr batch 18`;
Database changed
mysql> show tables;
+-------------------------------+
| Tables_in_new excelr batch 18 |
+-------------------------------+
| patients |
| student |
+-------------------------------+
2 rows in set (0.02 sec)

mysql> select * from student;


+------+-------+------+
| s_id | name | age |
+------+-------+------+
| 10 | Alex | 33 |
| 11 | Tony | 27 |
| 12 | Drake | 30 |
+------+-------+------+
3 rows in set (0.05 sec)

mysql> Alter table Student add column course varchar(111);


Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from student;


+------+-------+------+--------+
| s_id | name | age | course |
+------+-------+------+--------+
| 10 | Alex | 33 | NULL |
| 11 | Tony | 27 | NULL |
| 12 | Drake | 30 | NULL |
+------+-------+------+--------+
3 rows in set (0.00 sec)

mysql> Alter table student drop column age;


Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from student;


+------+-------+--------+
| s_id | name | course |
+------+-------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+-------+--------+
3 rows in set (0.00 sec)

mysql> desc student;


+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| s_id | int | YES | | NULL | |
| name | char(45) | YES | | NULL | |
| course | varchar(111) | YES | | NULL | |
+--------+--------------+------+-----+---------+-------+
3 rows in set (0.02 sec)
mysql> select * from student;
+------+-------+--------+
| s_id | name | course |
+------+-------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+-------+--------+
3 rows in set (0.00 sec)

mysql> Alter table student modify column name varchar(60);


Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> desc student;


+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| s_id | int | YES | | NULL | |
| name | varchar(60) | YES | | NULL | |
| course | varchar(111) | YES | | NULL | |
+--------+--------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> Alter table student change name s_name varchar(45);


Query OK, 3 rows affected (0.04 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from student;


+------+--------+--------+
| s_id | s_name | course |
+------+--------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+--------+--------+
3 rows in set (0.00 sec)

mysql> Alter table student rename to my_class;


Query OK, 0 rows affected (0.01 sec)

mysql> select * from student;


ERROR 1146 (42S02): Table 'new excelr batch 18.student' doesn't exist
mysql> select * from my_class;
+------+--------+--------+
| s_id | s_name | course |
+------+--------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+--------+--------+
3 rows in set (0.00 sec)

mysql> Rename table my_class to student;


Query OK, 0 rows affected (0.01 sec)

mysql> select * from my_class;


ERROR 1146 (42S02): Table 'new excelr batch 18.my_class' doesn't exist
mysql> select * from student;
+------+--------+--------+
| s_id | s_name | course |
+------+--------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+--------+--------+
3 rows in set (0.00 sec)

mysql> select 3+3;


+-----+
| 3+3 |
+-----+
| 6 |
+-----+
1 row in set (0.01 sec)

mysql> select 3*3;


+-----+
| 3*3 |
+-----+
| 9 |
+-----+
1 row in set (0.01 sec)

mysql> select 3-3;


+-----+
| 3-3 |
+-----+
| 0 |
+-----+
1 row in set (0.00 sec)

mysql> select 3/3;


+--------+
| 3/3 |
+--------+
| 1.0000 |
+--------+
1 row in set (0.00 sec)

mysql> select 3%3;


+------+
| 3%3 |
+------+
| 0 |
+------+
1 row in set (0.00 sec)

mysql> select 3^3;


+-----+
| 3^3 |
+-----+
| 0 |
+-----+
1 row in set (0.01 sec)

mysql> select 3 = NULL;


+----------+
| 3 = NULL |
+----------+
| NULL |
+----------+
1 row in set (0.01 sec)

mysql> select 3 is NULL;


+-----------+
| 3 is NULL |
+-----------+
| 0 |
+-----------+
1 row in set (0.00 sec)

mysql> select 3 is not NULL;


+---------------+
| 3 is not NULL |
+---------------+
| 1 |
+---------------+
1 row in set (0.00 sec)

mysql> select * from student;


+------+--------+--------+
| s_id | s_name | course |
+------+--------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
+------+--------+--------+
3 rows in set (0.00 sec)

mysql> insert into student values (13,'merlin','python');


Query OK, 1 row affected (0.01 sec)

mysql> select * from student;


+------+--------+--------+
| s_id | s_name | course |
+------+--------+--------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
+------+--------+--------+
4 rows in set (0.00 sec)

mysql> insert into student values (14,'John','excel'),(15,'Johnathan','Power BI'),


(16,'Sam','Tableau'),(17,'Ha
rry','MYSQL');
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Johnathan | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
+------+-----------+----------+
8 rows in set (0.00 sec)

mysql> insert into student (18,'Marry',NULL);


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'18,'Marry',NULL)' at line 1
mysql> insert into student values (18,'Marry',NULL);
Query OK, 1 row affected (0.01 sec)

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Johnathan | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | NULL |
+------+-----------+----------+
9 rows in set (0.00 sec)

mysql> insert into student (s_id,course) values (19,'Python');


Query OK, 1 row affected (0.01 sec)

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Tony | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Johnathan | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | NULL |
| 19 | NULL | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql> update student set s_name = "Lara" where s_id = 11;


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Lara | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Johnathan | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | NULL |
| 19 | NULL | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql> update student set s_name = "Alexander" where s_id = 15;


Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Lara | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Alexander | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | NULL |
| 19 | NULL | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql> update student set course = "excel" where course = NULL;


Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | NULL |
| 11 | Lara | NULL |
| 12 | Drake | NULL |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Alexander | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | NULL |
| 19 | NULL | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql> update student set course = "excel" where course is NULL;


Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> select * from student;
+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | excel |
| 11 | Lara | excel |
| 12 | Drake | excel |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Alexander | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | excel |
| 19 | NULL | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql> update student set s_name = "tony" where s_name is NULL;


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from student;


+------+-----------+----------+
| s_id | s_name | course |
+------+-----------+----------+
| 10 | Alex | excel |
| 11 | Lara | excel |
| 12 | Drake | excel |
| 13 | merlin | python |
| 14 | John | excel |
| 15 | Alexander | Power BI |
| 16 | Sam | Tableau |
| 17 | Harry | MYSQL |
| 18 | Marry | excel |
| 19 | tony | Python |
+------+-----------+----------+
10 rows in set (0.00 sec)

mysql>

You might also like