0% found this document useful (0 votes)
11 views

Database

The document shows the steps taken to connect to a MySQL database server and create, populate, modify and delete tables. It connects to the server, creates databases and tables, inserts, updates, alters and drops tables. It also shows commands to view table schemas and data.

Uploaded by

kushathashree
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Database

The document shows the steps taken to connect to a MySQL database server and create, populate, modify and delete tables. It connects to the server, creates databases and tables, inserts, updates, alters and drops tables. It also shows commands to view table schemas and data.

Uploaded by

kushathashree
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Enter password: ********

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


Your MySQL connection id is 26
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> create database MATRIX;


Query OK, 1 row affected (0.10 sec)

mysql> use MATRIX;


Database changed

mysql> create table NEO


-> (
-> eid int(5) primary key,
-> ename varchar(45) not null,
-> address char(50) not null,
-> phone bigint(15) unique,
-> email text(39) not null,
-> mobile bigint(16)
-> );
Query OK, 0 rows affected, 3 warnings (1.14 sec)

mysql> insert into NEO values(1,"ram k","bkt","01230","[email protected]","9810201"),


(2,"jens m","ktm","012465","[email protected]","98231343"),(3,"jame
w","ptn","0167747","[email protected]","9807654"),(4,"naruto
op","iilam","01424262","[email protected]","98111222"),(5,"hokage
sama","konoha","01983764","[email protected]","98076541");
Query OK, 5 rows affected (0.06 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> desc ne0;


ERROR 1146 (42S02): Table 'matrix.ne0' doesn't exist
mysql> desc neo;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| eid | int | NO | PRI | NULL | |
| ename | varchar(45) | NO | | NULL | |
| address | char(50) | NO | | NULL | |
| phone | bigint | YES | UNI | NULL | |
| email | tinytext | NO | | NULL | |
| mobile | bigint | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.07 sec)

mysql> select * from neo;


+-----+-------------+---------+---------+------------------+----------+
| eid | ename | address | phone | email | mobile |
+-----+-------------+---------+---------+------------------+----------+
| 1 | ram k | bkt | 1230 | [email protected] | 9810201 |
| 2 | jens m | ktm | 12465 | [email protected] | 98231343 |
| 3 | jame w | ptn | 167747 | [email protected] | 9807654 |
| 4 | naruto op | iilam | 1424262 | [email protected] | 98111222 |
| 5 | hokage sama | konoha | 1983764 | [email protected] | 98076541 |
+-----+-------------+---------+---------+------------------+----------+
5 rows in set (0.00 sec)

mysql> update neo set eid="100" where eid=1;


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

mysql> select * from neo;


+-----+-------------+---------+---------+------------------+----------+
| eid | ename | address | phone | email | mobile |
+-----+-------------+---------+---------+------------------+----------+
| 2 | jens m | ktm | 12465 | [email protected] | 98231343 |
| 3 | jame w | ptn | 167747 | [email protected] | 9807654 |
| 4 | naruto op | iilam | 1424262 | [email protected] | 98111222 |
| 5 | hokage sama | konoha | 1983764 | [email protected] | 98076541 |
| 100 | ram k | bkt | 1230 | [email protected] | 9810201 |
+-----+-------------+---------+---------+------------------+----------+
5 rows in set (0.00 sec)

mysql> alter table neo


-> add designation varchar(45);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> select * from neo;


+-----+-------------+---------+---------+------------------+----------
+-------------+
| eid | ename | address | phone | email | mobile | designation
|
+-----+-------------+---------+---------+------------------+----------
+-------------+
| 2 | jens m | ktm | 12465 | [email protected] | 98231343 | NULL
|
| 3 | jame w | ptn | 167747 | [email protected] | 9807654 | NULL
|
| 4 | naruto op | iilam | 1424262 | [email protected] | 98111222 | NULL
|
| 5 | hokage sama | konoha | 1983764 | [email protected] | 98076541 | NULL
|
| 100 | ram k | bkt | 1230 | [email protected] | 9810201 | NULL
|
+-----+-------------+---------+---------+------------------+----------
+-------------+
5 rows in set (0.00 sec)

mysql> update neo set designation="manager" where eid=2;


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

mysql> update neo set designation="jenitor" where eid=3;


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

mysql> update neo set designation="ceo" where eid=5;


Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update neo set designation="staff" where eid=4;
Query OK, 1 row affected (0.16 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> update neo set designation="employee" where eid=100;


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

mysql> select * from neo;


+-----+-------------+---------+---------+------------------+----------
+-------------+
| eid | ename | address | phone | email | mobile | designation
|
+-----+-------------+---------+---------+------------------+----------
+-------------+
| 2 | jens m | ktm | 12465 | [email protected] | 98231343 | manager
|
| 3 | jame w | ptn | 167747 | [email protected] | 9807654 | jenitor
|
| 4 | naruto op | iilam | 1424262 | [email protected] | 98111222 | staff
|
| 5 | hokage sama | konoha | 1983764 | [email protected] | 98076541 | ceo
|
| 100 | ram k | bkt | 1230 | [email protected] | 9810201 | employee
|
+-----+-------------+---------+---------+------------------+----------
+-------------+
5 rows in set (0.00 sec)

mysql> alter table neo


-> modify column address varchar(60);
Query OK, 5 rows affected (0.38 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> desc neo;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| eid | int | NO | PRI | NULL | |
| ename | varchar(45) | NO | | NULL | |
| address | varchar(60) | YES | | NULL | |
| phone | bigint | YES | UNI | NULL | |
| email | tinytext | NO | | NULL | |
| mobile | bigint | YES | | NULL | |
| designation | varchar(45) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> alter table neo change eid Employee_ID int(5);


Query OK, 0 rows affected, 1 warning (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 1

mysql> desc neo;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| Employee_ID | int | NO | PRI | NULL | |
| ename | varchar(45) | NO | | NULL | |
| address | varchar(60) | YES | | NULL | |
| phone | bigint | YES | UNI | NULL | |
| email | tinytext | NO | | NULL | |
| mobile | bigint | YES | | NULL | |
| designation | varchar(45) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> se
-> ;
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 'se' at
line 1
mysql> select * from neo;
+-------------+-------------+---------+---------+------------------+----------
+-------------+
| Employee_ID | ename | address | phone | email | mobile |
designation |
+-------------+-------------+---------+---------+------------------+----------
+-------------+
| 2 | jens m | ktm | 12465 | [email protected] | 98231343 |
manager |
| 3 | jame w | ptn | 167747 | [email protected] | 9807654 |
jenitor |
| 4 | naruto op | iilam | 1424262 | [email protected] | 98111222 |
staff |
| 5 | hokage sama | konoha | 1983764 | [email protected] | 98076541 | ceo
|
| 100 | ram k | bkt | 1230 | [email protected] | 9810201 |
employee |
+-------------+-------------+---------+---------+------------------+----------
+-------------+
5 rows in set (0.00 sec)

mysql> drop table neo;


Query OK, 0 rows affected (0.08 sec)

mysql> show tables;


Empty set (0.00 sec)

mysql> create database END GAME;


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 'GAME' at
line 1
mysql> create database ENDGAME;
Query OK, 1 row affected (0.06 sec)

mysql> use ENDGAME;


Database changed
mysql> create table avenger
-> (
-> id int(10)
-> );
Query OK, 0 rows affected, 1 warning (0.15 sec)

mysql> desc avenger;


+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| id | int | YES | | NULL | |
+-------+------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> select * from avenger;


Empty set (0.00 sec)

mysql> insert into avenger values(100);


Query OK, 1 row affected (0.08 sec)

mysql> select * from avenger;


+------+
| id |
+------+
| 100 |
+------+
1 row in set (0.00 sec)

mysql> drop database endgame;


Query OK, 1 row affected (0.17 sec)

mysql> show database endgame;


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 'database
endgame' at line 1
mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| matrix |
| mouse |
| mysql |
| performance_schema |
| sys |
+--------------------+
9 rows in set (0.02 sec)

mysql>

You might also like