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

Basic

The document details a series of MySQL commands executed for a database assignment, including creating a 'university' database, defining tables for students, courses, and enrollments, and performing various operations such as inserting, deleting, and altering data. It also covers user management by creating a new user and granting/revoking privileges. The document concludes with interactions in a 'libraryDB' database, showcasing tables for books, members, and borrowed books.

Uploaded by

ameykhodke430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Basic

The document details a series of MySQL commands executed for a database assignment, including creating a 'university' database, defining tables for students, courses, and enrollments, and performing various operations such as inserting, deleting, and altering data. It also covers user management by creating a new user and granting/revoking privileges. The document concludes with interactions in a 'libraryDB' database, showcasing tables for books, members, and borrowed books.

Uploaded by

ameykhodke430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

DBMS ASSIGNMENT 1

Date – January 23, 2025

mysql> show databases; -- Show all databases in MySQL Workbench


+--------------------+
| Database |
+--------------------+
| information_schema |
| librarydb |
| management |
| mysql |
| performance_schema |
| sakila |
| sql_data |
| syita |
| sys |
| world |
+--------------------+
10 rows in set (0.00 sec)

mysql> create database university; -- Create a new database named 'university'


Query OK, 1 row affected (0.00 sec)

mysql> show databases; -- Verify that 'university' is created


+--------------------+
| Database |
+--------------------+
| information_schema |
| librarydb |
| management |
| mysql |
| performance_schema |
| sakila |
| sql_data |
| syita |
| sys |
| university |
| world |
+--------------------+
11 rows in set (0.00 sec)

mysql> use university; -- Switch to the 'university' database


Database changed
mysql> create table student(roll_no integer primary key,name varchar(30),
address varchar(30), mob_no integer(11)); -- Create 'student' table with
columns and primary key
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> desc student; -- Describe the structure of 'student' table


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| roll_no | int | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
| mob_no | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> create table course(c_id integer, c_name char(20)); -- Create 'course'


table
Query OK, 0 rows affected (0.01 sec)

mysql> desc course; -- Describe the 'course' table structure


+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| c_id | int | YES | | NULL | |
| c_name | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> create table enroll(roll_no integer, c_id integer, date date); -- Create
'enroll' table to link students and courses
Query OK, 0 rows affected (0.01 sec)

mysql> desc enroll; -- Describe the 'enroll' table structure


+---------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------+------+-----+---------+-------+
| roll_no | int | YES | | NULL | |
| c_id | int | YES | | NULL | |
| date | date | YES | | NULL | |
+---------+------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> alter table course add primary key(c_id); -- Set 'c_id' as the primary
key for 'course' table
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table course rename to course_info; -- Rename 'course' table to


'course_info'
Query OK, 0 rows affected (0.01 sec)

mysql> desc course; -- Check 'course' table (should show an error since it was
renamed)
ERROR 1146 (42S02): Table 'university.course' doesn't exist

mysql> desc course_info; -- Describe the renamed table 'course_info'


+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| c_id | int | NO | PRI | NULL | |
| c_name | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table course_info add column duration integer; -- Add 'duration'
column to 'course_info'
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc course_info; -- Describe the renamed table 'course_info'
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| c_id | int | NO | PRI | NULL | |
| c_name | char(20) | YES | | NULL | |
| duration | int | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into student values(1,"Yash Dabhade","Jalna",785694123); --


Insert another record into 'student'
Query OK, 1 row affected (0.01 sec)

mysql> insert into student values(2,"Om Jejurkar","Shirdi",879645123); --


Insert another record into 'student'
Query OK, 1 row affected (0.00 sec)

mysql> insert into student values(3,"Soham


Deshmukh","Parali",987451236); -- Insert another record into 'student'
Query OK, 1 row affected (0.00 sec)

mysql> select * from student; -- Display all records from 'student'


+---------+----------------+---------+-----------+
| roll_no | name | address | mob_no |
+---------+----------------+---------+-----------+
| 1 | Yash Dabhade | Jalna | 785694123 |
| 2 | Om Jejurkar | Shirdi | 879645123 |
| 3 | Soham Deshmukh | Parali | 987451236 |
+---------+----------------+---------+-----------+
3 rows in set (0.00 sec)

mysql> insert into course_info values(111,"AIML",4); -- Insert a course into


'course_info'
Query OK, 1 row affected (0.00 sec)

mysql> insert into course_info values(222,"Cybersecurity",3); -- Insert


another course into 'course_info'
Query OK, 1 row affected (0.01 sec)

mysql> insert into course_info values(333,"Data science",3); -- Insert third


course into 'course_info'
Query OK, 1 row affected (0.00 sec)

mysql> select * from course_info; -- Display all records from 'course_info'


+------+---------------+----------+
| c_id | c_name | duration |
+------+---------------+----------+
| 111 | AIML | 4|
| 222 | Cybersecurity | 3|
| 333 | Data science | 3|
+------+---------------+----------+
3 rows in set (0.00 sec)

mysql> insert into enroll values(1,111,'24-01-25'); -- insert record into enroll


table
Query OK, 1 row affected (0.00 sec)

mysql> insert into enroll values(2,222,'25-01-25'); -- insert record into enroll


table
Query OK, 1 row affected (0.00 sec)

mysql> insert into enroll values(3,333,'26-01-25'); -- insert record into enroll


table
Query OK, 1 row affected (0.00 sec)

mysql> select * from enroll ; -- Display all records from 'enroll'


+---------+------+------------+
| roll_no | c_id | date |
+---------+------+------------+
| 1 | 111 | 2024-01-25 |
| 2 | 222 | 2025-01-25 |
| 3 | 333 | 2026-01-25 |
+---------+------+------------+
3 rows in set (0.00 sec)

mysql> alter table enroll add constraint fk_roll_no foreign key(roll_no)


references student(roll_no); -- Add foreign key constraint linking
'enroll.roll_no' to 'student.roll_no'
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> alter table enroll add constraint fk_course foreign key(c_id)


references course_info(c_id); -- Add foreign key linking 'enroll.c_id' to
'course_info.c_id'
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from student where roll_no = 1; -- Fetch student details where
roll_no is 1
+---------+--------------+---------+-----------+
| roll_no | name | address | mob_no |
+---------+--------------+---------+-----------+
| 1 | Yash Dabhade | Jalna | 785694123 |
+---------+--------------+---------+-----------+
1 row in set (0.00 sec)

mysql> delete from enroll where roll_no = 3; -- Delete enrollment of student


with roll_no 3
Query OK, 1 row affected (0.00 sec)

mysql> select * from enroll; -- Display updated enrollments


+---------+------+------------+
| roll_no | c_id | date |
+---------+------+------------+
| 1 | 111 | 2024-01-25 |
| 2 | 222 | 2025-01-25 |
+---------+------+------------+
2 rows in set (0.00 sec)

mysql> delete from student where roll_no = 3; -- Delete student with roll_no 3
Query OK, 1 row affected (0.01 sec)
mysql> select * from student; -- Display remaining students
+---------+--------------+---------+-----------+
| roll_no | name | address | mob_no |
+---------+--------------+---------+-----------+
| 1 | Yash Dabhade | Jalna | 785694123 |
| 2 | Om Jejurkar | Shirdi | 879645123 |
+---------+--------------+---------+-----------+
2 rows in set (0.00 sec)

mysql> delete from course_info where c_name = "Data science"; -- Delete


course named 'Data science'
Query OK, 1 row affected (0.00 sec)

mysql> select * from course_info; -- Verify that 'Data science' is deleted


+------+---------------+----------+
| c_id | c_name | duration |
+------+---------------+----------+
| 111 | AIML | 4|
| 222 | Cybersecurity | 3|
+------+---------------+----------+
2 rows in set (0.00 sec)

mysql> alter table enroll drop constraint fk_roll_no; -- Remove foreign key
constraint on 'roll_no' in 'enroll'
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> truncate table student; -- Delete all records from 'student' without
affecting table structure
Query OK, 0 rows affected (0.02 sec)

mysql> select * from student; -- Verify that 'student' table is empty


Empty set (0.00 sec)

mysql> select user from mysql.user;


+------------------+
| user |
+------------------+
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
+------------------+
4 rows in set (0.00 sec)

mysql> create user 'user1'@'localhost' identified by 'user123';


Query OK, 0 rows affected (0.02 sec)

mysql> select user from mysql.user;


+------------------+
| user |
+------------------+
| mysql.infoschema |
| mysql.session |
| mysql.sys |
| root |
| user1 |
+------------------+
5 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'user1'@'localhost';


Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

C:\Users\ameyk>mysql -u user1 -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.40 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 |
+--------------------+
| information_schema |
| librarydb |
| management |
| mysql |
| performance_schema |
| sakila |
| sql_data |
| syita |
| sys |
| university |
| world |
+--------------------+
11 rows in set (0.00 sec)

mysql> use libraryDB;


Database changed
mysql> show tables;
+---------------------+
| Tables_in_librarydb |
+---------------------+
| books |
| borrowedbooks |
| members |
+---------------------+
3 rows in set (0.01 sec)

mysql> select * from books;


+--------+-------------------+----------------+---------+-------+
| BOOKID | TITLE | Author | Price | stock |
+--------+-------------------+----------------+---------+-------+
| 1 | The Alchemist | Paul coleho | 299.99 | 10 |
| 2 | Atomic Values | James clear | 420.99 | 15 |
| 3 | clean code | Robert martin | 550.99 | 8|
| 4 | Rich dad poor dad | Robert kiyoski | 400.00 | 12 |
| 5 | The programmer | Andrew hunt | 4005.00 | 12 |
+--------+-------------------+----------------+---------+-------+
5 rows in set (0.02 sec)

mysql> select * from members;


+----------+----------------+------------------------+------------+
| MemberId | Name | Email | Joindate |
+----------+----------------+------------------------+------------+
| 1 | Om jejurkar | [email protected] | 2024-10-20 |
| 2 | Yash Dabhade | [email protected] | 2015-12-23 |
| 3 | Gaurav Gaikwad | [email protected] | 2002-05-24 |
| 4 | Sachin Rathod | [email protected] | 2011-01-24 |
| 5 | Emily Davis | [email protected] | 2003-01-24 |
+----------+----------------+------------------------+------------+
5 rows in set (0.01 sec)

mysql> select * from borrowedbooks


-> ;
+----------+----------+--------+------------+------------+
| Borrowid | Memberid | bookid | borrowdate | returndate |
+----------+----------+--------+------------+------------+
| 1| 1| 2 | 2025-01-30 | 2025-02-20 |
| 2| 2| 3 | 2025-02-15 | 2025-03-21 |
| 3| 3| 4 | 2025-02-15 | 2025-03-22 |
| 4| 2| 5 | 2025-03-14 | 2025-04-27 |
| 5| 3| 4 | 2025-04-14 | 2025-05-29 |
+----------+----------+--------+------------+------------+
5 rows in set (0.01 sec)

mysql> exit;
Bye

C:\Users\ameyk>mysql -u user1 -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.40 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> revoke all privileges on *.* from 'user1'@'localhost';


Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

C:\Users\ameyk>mysql -u user1 -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.40 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 |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+

You might also like