0% found this document useful (0 votes)
90 views9 pages

Create Database

1. The document shows the steps to create a student database and table, insert sample data, perform queries, updates, and deletions on the table. 2. Commands are used to create, alter, rename, and drop the database and table as needed to demonstrate functionality. 3. Sample data for students is inserted and selected from the table to show how it can be queried, updated, and manipulated as desired.

Uploaded by

Haseeb Pavaskar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
90 views9 pages

Create Database

1. The document shows the steps to create a student database and table, insert sample data, perform queries, updates, and deletions on the table. 2. Commands are used to create, alter, rename, and drop the database and table as needed to demonstrate functionality. 3. Sample data for students is inserted and selected from the table to show how it can be queried, updated, and manipulated as desired.

Uploaded by

Haseeb Pavaskar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

1.

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)

3.Create table student;


mysql> create table student (s_id varchar(15),
-> s_name varchar(15),
-> s_adress varchar(15),
-> s_marks varchar(15),
-> s_div varchar(15));
Query OK, 0 rows affected (0.20 sec)

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

| Null | Key | Default | Extra |

+----------+-------------+------+-----+---------+-------+
| s_id

| varchar(15) | YES |

| NULL |

| s_name | varchar(15) | YES |

| NULL |

| s_adress | varchar(15) | YES |

| NULL |

| s_marks | varchar(15) | YES |

| NULL |

| s_div | varchar(15) | YES |

| 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)

mysql> insert into student(s_id,s_name,s_adress,s_marks,s_div)


-> VALUES (2,'RAM','BORIVLI',70,'B');
Query OK, 1 row affected (0.07 sec)

mysql> insert into student(s_id,s_name,s_adress,s_marks,s_div)

-> VALUES (3,'RAHUL','MALAD',80,'A');


Query OK, 1 row affected (1.23 sec)

mysql> insert into student(s_id,s_name,s_adress,s_marks,s_div)


-> VALUES (4,'RAMBO','GOREGAON',75,'B');
Query OK, 1 row affected (0.07 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

mysql> select * from student;

+------+--------+----------+---------+-------+
| 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

mysql> select * from student;


+------+--------+----------+---------+-------+
| 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

| 4 | RAMBO | GOREGAON | 75

|
|B

+------+--------+----------+---------+-------+

4 rows in set (0.00 sec)

10.delete
mysql> delete from student
-> where s_id=4;
Query OK, 1 row affected (0.07 sec)

mysql> select * from student;


+------+--------+----------+---------+-------+
| 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)

11.drop

mysql> drop database stud;


Mysql> drop table stud;

12.rename

mysql> rename table student to student1;


Query OK, 0 rows affected (0.32 sec)

mysql> select * from student1;

+------+--------+----------+---------+-------+
| 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

mysql> select * from student;


+------+--------+----------+---------+-------+
| s_id | s_name | s_adrs | 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)

2.MODIFY

mysql> ALTER TABLE STUDENT


-> MODIFY s_id int;
Query OK, 3 rows affected (0.27 sec)
Records: 3 Duplicates: 0 Warnings: 0

3.add

mysql> alter table student


-> add s_age int;
Query OK, 3 rows affected (1.66 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from student;


+------+--------+----------+---------+-------+-------+
| s_id | s_name | s_adrs | s_marks | s_div | s_age |
+------+--------+----------+---------+-------+-------+
| 1 | RAJ | KANDIVLI | 90

|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

mysql> select * from student;


+------+--------+----------+---------+-------+
| s_id | s_name | s_adrs | 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)

5. PRIMARY KEY

mysql> ALTER TABLE STUDENT


-> ADD PRIMARY KEY (S_ID);
Query OK, 3 rows affected (1.55 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> DESCRIBE STUDENT;


+---------+-------------+------+-----+---------+-------+
| Field | Type

| Null | Key | Default | Extra |

+---------+-------------+------+-----+---------+-------+
| s_id | int(11)

| NO | PRI | 0

| s_name | varchar(15) | YES |


| s_adrs | varchar(30) | YES |
| s_marks | varchar(15) | YES |
| s_div | varchar(15) | YES |

| NULL |
| NULL |

|
|

| NULL |
| NULL |

|
|

+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

6.RENAME

mysql> ALTER TABLE STUDENT RENAME TO STUDENT1;


Query OK, 0 rows affected (3.60 sec)

You might also like