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

DBMS Mysql Assignment 1&2

The document describes a database assignment involving students' registration and course data. It includes: 1. Creating two tables - Registration with columns like name, roll number, branch, and Fetch with columns like name, roll number, id, subjects. 2. Inserting sample data into both tables and applying constraints like primary keys and data types. 3. Altering the tables by adding a column for college name. 4. Dropping the tables. 5. Various DML commands like insert, update, select to manipulate the data in the tables.

Uploaded by

Avi Srivastava
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)
130 views

DBMS Mysql Assignment 1&2

The document describes a database assignment involving students' registration and course data. It includes: 1. Creating two tables - Registration with columns like name, roll number, branch, and Fetch with columns like name, roll number, id, subjects. 2. Inserting sample data into both tables and applying constraints like primary keys and data types. 3. Altering the tables by adding a column for college name. 4. Dropping the tables. 5. Various DML commands like insert, update, select to manipulate the data in the tables.

Uploaded by

Avi Srivastava
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/ 5

DBMS MYSQL

ASSIGNMENT 1 & 2

Name: Arj Srivastava


 
Date: 16/6/21
 
Roll No : 191390
 
Branch: CS-47

Faculty: Dr. Himanshu Jindal

Create table name registration having columns name, rollno, branch,


semester, stream, contactno, address.
Create another table fetch having columns name, rollno, branch, id, age,
subject1, subject2, subject3

1 - Insert 5-10 values for each table. Implement DDL and DML commands on
each table.
2 - put constraints as primary key for name, rollno in registration with
condition that semester would be >1, address will be restricted to himchal
pradesh and setting default value of stream as CSE/IT
3 - Access primary keys in fetch table fill the data in both tables by setting NOT
NULL constraints.

Implement and provide each query against each command with dropping or
altering constraints of table as well as records of table using DDl and DML.
Answer
use db1;
-- ** DML Queries ** --

-- DDL Query Creating Table --

create table Registration_data(


Student_Name varchar(50) not null ,
Roll_No int not null,
Branch varchar(50) ,
Semester varchar(20) check(Semester>1),
Stream varchar(40) default "CSE/IT",
Contact_No int8(10),
Address varchar(500),
primary key (Student_Name, Roll_No)
);

create table Fetch_data(


Student_Name varchar(50) references Registration_data(Student_Name),
Roll_No int references Registration_data(Roll_No),
Branch varchar(50) ,
ID int,
Age int,
Subject_1 varchar(50),
Subject_2 varchar(50),
Subject_3 varchar(50)
);

-- DDL Query Altering a Collumn in Table --

alter table Registration_data

2
add column Collage_Name varchar(50) after Branch ;

alter table Fetch_data


add column Collage_Name varchar(50) after Branch ;

-- DDL Query Droping the Table --

drop table Registration_data;


drop table Fetch_data;

-- ** DML Queries ** --

-- DML Query Inserting Data to the Table --

insert into Registration_data(Student_Name, Roll_No, Branch, Semester, Contact_No)


values
("Mohit Gautam", 191385, "Computer Scirnce", 2, 1665489213),
("Manan Mehta", 191386, "Computer Scirnce", 2, 1234567890),
("Sarthak Kumar", 191387, "Computer Scirnce", 2, 7894561230),
("Shaurya Awasthi", 191388, "Computer Scirnce", 2, 0654789123),
("Shreya Srivastava", 191389, "Computer Scirnce", 2, 5910234786),
("Arj Srivastava", 191390, "Computer Scirnce", 2, 7565996917),
("Achyut Tiwari", 191391, "Computer Scirnce", 2, 3512647890),
("Akshat Tripathi", 191392, "Computer Scirnce", 2, 8521479603),
("Yash Bhradwaj", 191398, "Computer Scirnce", 2, 9510236487),
("Shubham Chaturvedi", 191408, "Computer Scirnce", 2, 8547952605)
;

insert into Fetch_data(Student_Name, Roll_No, Branch, ID, Age, Subject_1, Subject_2, Subject_3)
values
("Mohit Gautam", 191385,"Computer Science", 385, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),

3
("Manan Mehta", 191386,"Computer Science", 386, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Sarthak Kumar", 191387,"Computer Science", 387, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Shaurya Awasthi", 191388,"Computer Science", 388, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Shreya Srivastava", 191389,"Computer Science", 389, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Arj Srivastava", 191390,"Computer Science", 390, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Achyut Tiwari", 191391,"Computer Science", 391, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Akshat Tripathi",191392,"Computer Science", 392, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Yash Bhradwaj",191398,"Computer Science", 398, 20,"Database Mangement System", "Model
Simulations & Technique", "Python"),
("Shubham Chaturvedi", 191408,"Computer Science", 408, 20,"Database Mangement System", "Model
Simulations & Technique", "Python")
;

-- DML Query Updating the table --

update Registration_data
set Address = "Himachal Pradesh";

update Registration_data
set Collage_Name = "JUIT";

update Fetch_data
set Collage_Name = "JUIT";

-- DML Query Selecting the Data from Table --

select * from db1.Registration_data;


select * from db1.Fetch_data;
4
5

You might also like