Uploaded by 1904261

Mysql lec summary

advertisement
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.28 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 |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create databases;
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' at line 1
mysql> create databases School;
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 School' at line 1
mysql> create database School;
Query OK, 1 row affected (0.06 sec)
mysql> show databases
-> \c
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> use School;
Database changed
mysql> show tables;
Empty set (0.13 sec)
mysql> use School;
Database changed
mysql> create table Student(ID int,Name varchar(100),Age int);
Query OK, 0 rows affected (0.39 sec)
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| student |
+------------------+
1 row in set (0.00 sec)
mysql> describe Student;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| ID | int | YES | | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Age | int | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> create table Faculty(Faculty_ID int primary key,Name varchar(100),Course varchar(100) Not Null,Salary int default 1000);
Query OK, 0 rows affected (0.05 sec)
mysql> describe Faculty;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| Faculty_ID | int | NO | PRI | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Course | varchar(100) | NO | | NULL | |
| Salary | int | YES | | 1000 | |
+------------+--------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
mysql> insert into Student values(101,"Divyanshu",20);
Query OK, 1 row affected (0.03 sec)
mysql> insert into Student values(102,"Divya",30);
Query OK, 1 row affected (0.01 sec)
mysql> insert into Student(ID,Name) values(103,"Aryan");
Query OK, 1 row affected (0.02 sec)
mysql> select * from Student;
+------+-----------+------+
| ID | Name | Age |
+------+-----------+------+
| 101 | Divyanshu | 20 |
| 102 | Divya | 30 |
| 103 | Aryan | NULL |
+------+-----------+------+
3 rows in set (0.01 sec)
mysql> describe Faculty;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| Faculty_ID | int | NO | PRI | NULL | |
| Name | varchar(100) | YES | | NULL | |
| Course | varchar(100) | NO | | NULL | |
| Salary | int | YES | | 1000 | |
+------------+--------------+------+-----+---------+-------+
4 rows in set (0.03 sec)
mysql> insere into Faculty values(101,"Lalatendu","Physics",20000);
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 'insere into Faculty values(101,"Lalatendu","Physics",20000)' at line 1
mysql> insert into Faculty values(101,"Lalatendu","Physics",20000);
Query OK, 1 row affected (0.02 sec)
mysql> select * from Faculty;
+------------+-----------+---------+--------+
| Faculty_ID | Name | Course | Salary |
+------------+-----------+---------+--------+
| 101 | Lalatendu | Physics | 20000 |
+------------+-----------+---------+--------+
1 row in set (0.00 sec)
mysql> insert into Faculty (Faculty_ID,Name) values(102,"B.B Mishra");
ERROR 1364 (HY000): Field 'Course' doesn't have a default value
mysql> insert into Faculty (Faculty_ID,Name,course) values(102,"B.B Mishra","Math");
Query OK, 1 row affected (0.02 sec)
mysql> select * from Faculty;
+------------+------------+---------+--------+
| Faculty_ID | Name | Course | Salary |
+------------+------------+---------+--------+
| 101 | Lalatendu | Physics | 20000 |
| 102 | B.B Mishra | Math | 1000 |
+------------+------------+---------+--------+
2 rows in set (0.00 sec)
mysql>
Download