SQL QUARY EXAMPLES
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 8.0.37 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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 |
+-------------------------+
| aktu_ka_database |
| college_ka_database |
| dosti |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
| sys |
+-------------------------+
16 rows in set (0.02 sec)
mysql> DROP dosti;
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 'dosti' at line 1
mysql> drop database dosti;
Query OK, 1 row affected (0.10 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college_ka_database |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
| sys |
+-------------------------+
15 rows in set (0.00 sec)
mysql> drop databases sys,mysql;
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 'databases sys,mysql' at line 1
mysql> drop databases dosti;
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 'databases dosti' at line 1
mysql> drop databases sys;
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 'databases sys' at line 1
mysql> DROP DATABASE sys;
Query OK, 101 rows affected (0.41 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college_ka_database |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
14 rows in set (0.00 sec)
mysql> CREATE DATABASE Data_Science;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college_ka_database |
| data_science |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
15 rows in set (0.00 sec)
mysql> use database data_science;
ERROR 1049 (42000): Unknown database 'database'
mysql> use data_science;
Database changed
mysql> create table data_science_student_table;
ERROR 4028 (HY000): A table must have at least one visible column.
mysql> create table datasciencestudent;
ERROR 4028 (HY000): A table must have at least one visible column.
mysql> use data_science;
Database changed
mysql> create table data;
ERROR 4028 (HY000): A table must have at least one visible column.
mysql> CREATE TABLE data(
-> id INT UNIQUE
-> );
Query OK, 0 rows affected (0.05 sec)
mysql> INSERT INTO data VALUES(101);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO data VALUES(102);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM data;
+------+
| id |
+------+
| 101 |
| 102 |
+------+
2 rows in set (0.00 sec)
mysql> INSERT INTO data VALUES
->
-> (103);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO data VALUES(103);
ERROR 1062 (23000): Duplicate entry '103' for key 'data.id'
mysql> INSERT INTO data VALUES(104);
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM data;
+------+
| id |
+------+
| 101 |
| 102 |
| 103 |
| 104 |
+------+
4 rows in set (0.00 sec)
mysql> CREATE TABLE data(
-> name VARCHAR(50),
-> rollno INT NOT NULL);
ERROR 1050 (42S01): Table 'data' already exists
mysql> SELECT * TABLE FROM data_science;
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 'TABLE FROM data_science' at line 1
mysql> alter table data add column name varchar(50) after id;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select*from data;
+------+------+
| id | name |
+------+------+
| 101 | NULL |
| 102 | NULL |
| 103 | NULL |
| 104 | NULL |
+------+------+
4 rows in set (0.00 sec)
mysql>
mysql> alter table data add column rollno int before name;
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 'before name' at line 1
mysql> alter table data add column rollno int after name;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select*from data;
+------+------+--------+
| id | name | rollno |
+------+------+--------+
| 101 | NULL | NULL |
| 102 | NULL | NULL |
| 103 | NULL | NULL |
| 104 | NULL | NULL |
+------+------+--------+
4 rows in set (0.00 sec)
mysql> select rollno from data;
+--------+
| rollno |
+--------+
| NULL |
| NULL |
| NULL |
| NULL |
+--------+
4 rows in set (0.00 sec)
mysql> select name from data values
-> ("Ravi singh");
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 'values
("Ravi singh")' at line 1
mysql> INSERT INTO data (name, rollno) VALUES (value1, value2, value3, etc);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> INSERT INTO data (name, rollno)
-> VALUES("RAVI KUMAR SINGH",67),
-> VALUES("KISHAN KUMAR PRAJAPATI",43),
-> VALUES("RAHUL SINGH",22);
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 'VALUES("KISHAN KUMAR PRAJAPATI",43),
VALUES("RAHUL SINGH",22)' at line 3
mysql> INSERT INTO data (name, rollno)
-> VALUES("RAVI KUMAR SINGH",67);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT*FROM data;
+------+------------------+--------+
| id | name | rollno |
+------+------------------+--------+
| 101 | NULL | NULL |
| 102 | NULL | NULL |
| 103 | NULL | NULL |
| 104 | NULL | NULL |
| NULL | RAVI KUMAR SINGH | 67 |
+------+------------------+--------+
5 rows in set (0.00 sec)
mysql> create database if not exist college;
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 'exist college' at line 1
mysql> CREATE DATABASE IF NOT EXISTS college;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college |
| college_ka_database |
| data_science |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
16 rows in set (0.00 sec)
mysql> CREATE DATABASE IF NOT EXISTS college;
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college |
| college_ka_database |
| data_science |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
16 rows in set (0.00 sec)
mysql> CREATE DATABASE IF NOT EXISTS prema;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college |
| college_ka_database |
| data_science |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| mysql |
| performance_schema |
| prema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
17 rows in set (0.00 sec)
mysql> create database if not exists madhubala;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+-------------------------+
| Database |
+-------------------------+
| aktu_ka_database |
| college |
| college_ka_database |
| data_science |
| information_schema |
| jai_bajgrang_bali_ka_db |
| kishan_ka_database |
| library |
| library_ka_database |
| madhubala |
| mysql |
| performance_schema |
| prema |
| ravi_kumar_singh_db |
| ravi_singh db |
| student_db |
| student_ka_database |
| students_details_db |
+-------------------------+
18 rows in set (0.00 sec)
mysql> create table emp(
-> id int ,
-> salery int default 25000);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into emp(id) values(101);
Query OK, 1 row affected (0.01 sec)
mysql> select *from emp;
+------+--------+
| id | salery |
+------+--------+
| 101 | 25000 |
+------+--------+
1 row in set (0.00 sec)
mysql>
Comments