Create Database
Create Database
CREATE DATABASE
create database student;
(It will create the database as student)
2.USE
mysql> use student;
Database changed
(Whenever we want to use the database we have to use the statement use so wecan changed the
content in it)
4.show databases;
mysql> show databases;
+--------------------+
| Database
+--------------------+
| information_schema |
| mysql
| stud
| student
|
|
|
| test
+--------------------+
5 rows in set (0.04 sec)
5.DESCRIBE STUDENT;
mysql> describe student;
+----------+-------------+------+-----+---------+-------+
| Field | Type
+----------+-------------+------+-----+---------+-------+
| s_id
| varchar(15) | YES |
| NULL |
| NULL |
| NULL |
| NULL |
| NULL |
+----------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
6.INSERT
mysql> insert into student(s_id,s_name,s_adress,s_marks,s_div)
-> values (1,'raj','borivli',90,'A');
Query OK, 1 row affected (3.59 sec)
7.SELECT
mysql> SELECT * FROM STUDENT;
+------+--------+----------+---------+-------+
| s_id | s_name | s_adress | s_marks | s_div |
+------+--------+----------+---------+-------+
| 1 | raj
| borivli
| 90
|A
| 2 | RAM
| BORIVLI | 70
|B
| 3 | RAHUL
| MALAD | 80
|A
| 4 | RAMBO | GOREGAON | 75 | B
+------+--------+----------+---------+-------+
4 rows in set (0.00 sec)
8. update
mysql> UPDATE STUDENT
-> SET s_name= UPPER(s_name);
Query OK, 1 row affected (0.06 sec)
Rows matched: 4 Changed: 1 Warnings: 0
+------+--------+----------+---------+-------+
| s_id | s_name | s_adress | s_marks | s_div |
+------+--------+----------+---------+-------+
| 1 | RAJ
| borivli
90
| 2 | RAM
| BORIVLI
| 70
|B
| MALAD
| 80
|A
| 3 | RAHUL
|A
| 4 | RAMBO | GOREGAON | 75
|B
+------+--------+----------+---------+-------+
4 rows in set (0.00 sec)
9. where
mysql> update student
-> set s_adress='KANDIVLI'
-> WHERE s_id=1;
Query OK, 1 row affected (1.57 sec)
Rows matched: 1 Changed: 1 Warnings: 0
|A
| 2 | RAM | BORIVLI | 70
|B
| 3 | RAHUL | MALAD | 80
|A
| 4 | RAMBO | GOREGAON | 75
|
|B
+------+--------+----------+---------+-------+
10.delete
mysql> delete from student
-> where s_id=4;
Query OK, 1 row affected (0.07 sec)
|A
| 2 | RAM | BORIVLI | 70
|B
| 3 | RAHUL | MALAD | 80
|A
+------+--------+----------+---------+-------+
3 rows in set (0.00 sec)
11.drop
12.rename
+------+--------+----------+---------+-------+
| s_id | s_name | s_adress | s_marks | s_div |
+------+--------+----------+---------+-------+
| 1 | RAJ | KANDIVLI | 90
|A
| 2 | RAM | BORIVLI | 70
|B
| 3 | RAHUL | MALAD | 80
|A
+------+--------+----------+---------+-------+
3 rows in set (0.00 sec)
12. ALTER
1.CHANGE
mysql> alter table student
-> change s_adress s_adrs varchar(30);
Query OK, 3 rows affected (0.39 sec)
Records: 3 Duplicates: 0 Warnings: 0
|A
| 2 | RAM | BORIVLI | 70
|B
| 3 | RAHUL | MALAD | 80
|A
+------+--------+----------+---------+-------+
3 rows in set (0.00 sec)
2.MODIFY
3.add
|A
| NULL |
| 2 | RAM | BORIVLI | 70
|B
| NULL |
| 3 | RAHUL | MALAD | 80
|A
| NULL |
+------+--------+----------+---------+-------+-------+
3 rows in set (0.00 sec)
4. DROP
mysql> alter table student
-> drop s_age
-> ;
Query OK, 3 rows affected (0.25 sec)
Records: 3 Duplicates: 0 Warnings: 0
|A
| 2 | RAM | BORIVLI | 70
|B
| 3 | RAHUL | MALAD | 80
|A
+------+--------+----------+---------+-------+
3 rows in set (0.00 sec)
5. PRIMARY KEY
+---------+-------------+------+-----+---------+-------+
| s_id | int(11)
| NO | PRI | 0
| NULL |
| NULL |
|
|
| NULL |
| NULL |
|
|
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
6.RENAME