Untitled
gec@gec-H410M-H-V2:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.7.33-0ubuntu0.16.04.1 (Ubuntu) Copyright (c) 2000, 2021, 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> create database akshat; Query OK, 1 row affected (0.00 sec) mysql> use database akshat; ERROR 1049 (42000): Unknown database 'database' mysql> use akshat; Database changed mysql> use database; ERROR 1049 (42000): Unknown database 'database' mysql> create database akshat; ERROR 1007 (HY000): Can't create database 'akshat'; database exists mysql> use database; ERROR 1049 (42000): Unknown database 'database' mysql> use akshat; Database changed mysql> create table student; ERROR 1113 (42000): A table must have at least 1 column mysql> create table student(Name VARCHAR(20), Branch char(10),Regd.No. int); 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 'int)' at line 1 mysql> create table student(Name VARCHAR(20), Branch CHAR(10),Regd.No. INT); 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 'INT)' at line 1 mysql> create table student(Name VARCHAR(20), Branch CHAR(10), Regd.No. INT); 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 'INT)' at line 1 mysql> create table student(Name VARCHAR(20), Branch CHAR(10), Regd_No INT); Query OK, 0 rows affected (0.27 sec) mysql> insert into student values("rahul", "cse", 101) -> insert into student values("rahul", "cse", 101); 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 'insert into student values("rahul", "cse", 101)' at line 2 mysql> insert into student values("rahul", "cse", 101); Query OK, 1 row affected (0.05 sec) mysql> insert into student values("raj", "civil", 102); Query OK, 1 row affected (0.03 sec) mysql> insert into student values("deepak", "aiml", 103); Query OK, 1 row affected (0.03 sec) mysql> insert into student values("ansul", "ds", 104); Query OK, 1 row affected (0.02 sec) mysql> insert into student values("ansul", "mech", 105); Query OK, 1 row affected (0.04 sec) mysql> insert into student values("hemant", "mca", 106); Query OK, 1 row affected (0.05 sec) mysql> insert into student values("arun", "mba", 106); Query OK, 1 row affected (0.03 sec) mysql> insert into student values("rishav", "bca", 106); Query OK, 1 row affected (0.04 sec) mysql> insert into student values("akshat", "cse", 107); Query OK, 1 row affected (0.03 sec) mysql> select * from student; +--------+--------+---------+ | Name | Branch | Regd_No | +--------+--------+---------+ | rahul | cse | 101 | | raj | civil | 102 | | deepak | aiml | 103 | | ansul | ds | 104 | | ansul | mech | 105 | | hemant | mca | 106 | | arun | mba | 106 | | rishav | bca | 106 | | akshat | cse | 107 | +--------+--------+---------+ 9 rows in set (0.00 sec) mysql> select Name, Branch from student; +--------+--------+ | Name | Branch | +--------+--------+ | rahul | cse | | raj | civil | | deepak | aiml | | ansul | ds | | ansul | mech | | hemant | mca | | arun | mba | | rishav | bca | | akshat | cse | +--------+--------+ 9 rows in set (0.00 sec) mysql> select Name from student; +--------+ | Name | +--------+ | rahul | | raj | | deepak | | ansul | | ansul | | hemant | | arun | | rishav | | akshat | +--------+ 9 rows in set (0.00 sec) mysql> select * from student where name = "akshat"; +--------+--------+---------+ | Name | Branch | Regd_No | +--------+--------+---------+ | akshat | cse | 107 | +--------+--------+---------+ 1 row in set (0.02 sec) mysql> insert into student values("akshay", "ds", 107); Query OK, 1 row affected (0.03 sec) mysql> select * from student where Regd_No = 107; +--------+--------+---------+ | Name | Branch | Regd_No | +--------+--------+---------+ | akshat | cse | 107 | | akshay | ds | 107 | +--------+--------+---------+ 2 rows in set (0.00 sec) mysql> alter table student add(Math_mark int); Query OK, 0 rows affected (0.58 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from student; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | rahul | cse | 101 | NULL | | raj | civil | 102 | NULL | | deepak | aiml | 103 | NULL | | ansul | ds | 104 | NULL | | ansul | mech | 105 | NULL | | hemant | mca | 106 | NULL | | arun | mba | 106 | NULL | | rishav | bca | 106 | NULL | | akshat | cse | 107 | NULL | | akshay | ds | 107 | NULL | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> update student set Math_mark = 97 where Name = "akshat"; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from student; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | rahul | cse | 101 | NULL | | raj | civil | 102 | NULL | | deepak | aiml | 103 | NULL | | ansul | ds | 104 | NULL | | ansul | mech | 105 | NULL | | hemant | mca | 106 | NULL | | arun | mba | 106 | NULL | | rishav | bca | 106 | NULL | | akshat | cse | 107 | 97 | | akshay | ds | 107 | NULL | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> update student set Math_mark = 87 where Name = "rahul"; Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update student set Math_mark = 85 where Name = "raj"; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from student; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | rahul | cse | 101 | 87 | | raj | civil | 102 | 85 | | deepak | aiml | 103 | NULL | | ansul | ds | 104 | NULL | | ansul | mech | 105 | NULL | | hemant | mca | 106 | NULL | | arun | mba | 106 | NULL | | rishav | bca | 106 | NULL | | akshat | cse | 107 | 97 | | akshay | ds | 107 | NULL | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> update student set Math_mark = 84 where Name = "deepak"; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update student set Math_mark = 95 where Name = "ansul"; Query OK, 2 rows affected (0.03 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update student set Math_mark = 83 where Name = "hemant"; Query OK, 1 row affected (0.04 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update student set Math_mark = 89 where Name = "arun"; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update student set Math_mark = 78 where Name = "rishav"; Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from student; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | rahul | cse | 101 | 87 | | raj | civil | 102 | 85 | | deepak | aiml | 103 | 84 | | ansul | ds | 104 | 95 | | ansul | mech | 105 | 95 | | hemant | mca | 106 | 83 | | arun | mba | 106 | 89 | | rishav | bca | 106 | 78 | | akshat | cse | 107 | 97 | | akshay | ds | 107 | NULL | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> select * from student order by Math_mark; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | akshay | ds | 107 | NULL | | rishav | bca | 106 | 78 | | hemant | mca | 106 | 83 | | deepak | aiml | 103 | 84 | | raj | civil | 102 | 85 | | rahul | cse | 101 | 87 | | arun | mba | 106 | 89 | | ansul | ds | 104 | 95 | | ansul | mech | 105 | 95 | | akshat | cse | 107 | 97 | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> select * from student order by Regd_No by desc; 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 'by desc' at line 1 mysql> select * from student order by Regd_No by dsc; 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 'by dsc' at line 1 mysql> select * from student order by Regd_No desc; +--------+--------+---------+-----------+ | Name | Branch | Regd_No | Math_mark | +--------+--------+---------+-----------+ | akshat | cse | 107 | 97 | | akshay | ds | 107 | NULL | | hemant | mca | 106 | 83 | | arun | mba | 106 | 89 | | rishav | bca | 106 | 78 | | ansul | mech | 105 | 95 | | ansul | ds | 104 | 95 | | deepak | aiml | 103 | 84 | | raj | civil | 102 | 85 | | rahul | cse | 101 | 87 | +--------+--------+---------+-----------+ 10 rows in set (0.00 sec) mysql> select count(Regd_No) from student; +----------------+ | count(Regd_No) | +----------------+ | 10 | +----------------+ 1 row in set (0.00 sec) mysql> select count(distinct (branch)) from student; +--------------------------+ | count(distinct (branch)) | +--------------------------+ | 8 | +--------------------------+ 1 row in set (0.00 sec) mysql> select sum(Math_mark) from student; +----------------+ | sum(Math_mark) | +----------------+ | 793 | +----------------+ 1 row in set (0.00 sec) mysql> select max(Math_mark) from student; +----------------+ | max(Math_mark) | +----------------+ | 97 | +----------------+ 1 row in set (0.00 sec) mysql> select min(Math_mark) from student; +----------------+ | min(Math_mark) | +----------------+ | 78 | +----------------+ 1 row in set (0.00 sec) mysql> select avg(Math_mark) from student; +----------------+ | avg(Math_mark) | +----------------+ | 88.1111 | +----------------+ 1 row in set (0.00 sec) mysql> ^C mysql> ALTER TABLE student RENAME COLUMN math_mark to mathmark; 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 'COLUMN math_mark to mathmark' at line 1 mysql> ALTER student RENAME COLUMN math_mark to mathmark; 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 'student RENAME COLUMN math_mark to mathmark' at line 1 mysql> ^C mysql>
Leave a Comment