DBMS LAB FINAL.doc
DBMS LAB FINAL.doc
1. Write queries to create tables for e-shopping database with the specified fields
Customer (custid,custname,address,state,gender)
Purchase(purchase_order_id, custid, purchase_date, purchase_amount)
3. Write a query to add the new column dateofbirth in the customer table
4. Write a query to change the size of the address to 30 in the customer table
6. Write a query to add the primary key constraint for the fields custid, purchaseorderid
7. Write a query to create a new table purchaseorder from the existing table purchase
11. Write a query to drop the primary key constraint for custid
12. Write a query to add the table level primary key constraint for the field custid
13. Write a query to add the foreign key constraints for custid in the purchaseorder table
which refer the custid in the customer table
DATE:
1. Create the above tables with the mapping given above and specify the primary key constraint
which is underlined and specify the foreign key.
MYSQL>create table student_41(regno varchar(90) primary key,name varchar(20),DOJ
date,branch varchar(20));
3. Write a query to display the name and branch from STUDENT_XX table.
mysql> select name,branch from student_41;
4. Write a query to display the unique value of branch from STUDENT_XX table.
mysql> select distinct branch from student_41;
5. Write a query to list the student detail who belongs to the CSE department in STUDENT_XX
table.
mysql> select * from student_41 where branch='CSE';
Reg No: 912221104006
7. Write a query to display the student details where regno=’06c02’ and name=’bala’.
Mysql>select * from student_41 where branch='CSE' and regno=’06c02;
8. Write a query to display the student details order by (ascending) name in STUDENT_XX table.
Mysql>select * from student_41 order by name asc;
10. Write a query to display the regno, name from STUDENT_XX table where doj is 09-feb-11.
11. Write a query to retrieve all the details from the STUDENT_XX table whose name starts with A.
12. Write a query to retrieve all the details from the STUDENT_XX table whose name ends with A.
13. Write a query to retrieve all the records from the STUDENT_XX table which does not have
‘VA’.
14. Write a query to display the months between DOJ and till date.
MYSQL> select * from student_41 where doj between '2011-01-11' and current_date();
15. Write a query to update the total marks in MARK_XX table and display the MARK_XX values.
MYSQL> update mark_41 set total=sub1+sub2+sub3;
16. Write a query to display only those rows whose total ranges between 150 and 200.
MYSQL> select * from mark_41 where total between 150 and 200;
Reg No: 912221104006
17. Write a query to update the result column in MARK_XX table which holds the following
condition: sub1>=50,sub2>=50&sub3>=50 (PASS) Else (FAIL). Display the table values after
gets updated.
MYSQL> update mark_41 set result=case
2 when(sub1>=50 and sub2>=50 and sub3>=50)
3 then 'pass'
4 else 'fail'
5 end;
18. Write a query to display the mark details where total is greater than 200.
MYSQL> select * from mark_41 where total>200;
19. Write a query to display the mark details where total not in 240.
MYSQL> select * from mark_41 where total<>240;
20. Write a query to delete the row from STUDENT_XX table where regno=’06it02’.
MYSQL> delete from mark_41 where regno='06it02';
MYSQL> delete from student_41 where regno='06it02';
Reg No: 912221104006
2. Write a query to list the number of departments available in the faculty table.
mysql> select count(distinct dept_name) from faculty;
6. Write a query to get the average salary and number of faculties working in the CSE
department.
mysql> select avg(salary),count(*) from faculty where dept_name='CSE';
Reg No: 912221104006
7. Write a query to get the maximum, minimum, sum, average salary of all faculties.
mysql> select max(salary),min(salary),sum(salary),avg(salary) from faculty;
8. Write a query to get the maximum, minimum, sum, average salary of all faculties
working in the IT department.
mysql> select max(salary),min(salary),sum(salary),avg(salary) from faculty where
dept_name='IT';
10. Write a query to get the number of faculties with the same position in CSE
department.
mysql> select position,dept_name,count(*) from faculty group by position,dept_name
having dept_name='CSE';
11. Write a query to get the department name and the total salary payable in each
department.
Reg No: 912221104006
12. Write a query to get the job id and maximum salary of the faculties where maximum
salary is greater than or equal to $5000.
mysql> select faculty_id,max(salary) from faculty group by faculty_id having
max(salary)>=5000;
Reg No: 912221104006
Reg No: 912221104006
1. Write a query to display the regno, name, result from student_xx and
mark_xx table.
mysql> select a.regno,name,result from student01 a,mark01 b where a.regno=b.regno;
2. Write a query to display the regno, name, result of CSE & IT from
student_xx and mark_xx table.
mysql> select a.regno,name,result from student01 a,mark01 b where a.regno=b.regno
and branch in('CSE');
3. Write a query to select regno, name, branch, total from mark_xx and not
in student_xx using both the tables.
Reg No: 912221104006
4. Write a query to select regno, name, branch, total from student_xx and not
in mark_xx tables.
Mysql>select a.regno,name,branch,total from student01 a left outer join mark01
b on a.regno=b.regno;
5. Write a query to select regno, name, branch, total from both the
tables. Mysql>select a.regno,name,branch,total
From student01 a
Cross join mark01 b
Where a.regno=b.regno;
Book
ISBN Title Author_name Publisher_name Pub_Year Unit_Price
1001 Oracle Arora PHI 2004 399
1002 DBMS Silberschatz McGrawHill 2000 400
2001 Unix Kapoor SciTech 2002 270
2002 ADBMS Berson Pearson 2004 550
Author
Author_name Country
Arora U.s
Silberschatz Asia
Kapoor Canada
Berson Germany
E.Navathe England
Banu India
1. Create the above-mentioned tables and populate the values given.
Mysql>create table book01(isbn int,title varchar(90),author_name
varchar(90),pub_name varchar(90),pub_year date,unit_price int);
Mysql>insert into
book01(isbn,title,author_name,pub_name,pub_year,unit_price)values(1001,
‘oracle’,‘Arora’, ‘PHI’, ‘2004’, 399);
Mysql>insert into
book01(isbn,title,author_name,pub_name,pub_year,unit_price)values(1002,
‘DBMS’, ‘silberschatz’,‘McGrawHill’, ‘2000’,400);
Mysql>insert into
book0@(isbn,title,author_name,pub_name,pub_year,unit_price)values(2001,
‘unix’, ‘Kapoor’, ‘scitech’, 2002,270);
Mysql>insert into
book01(isbn,title,author_name,pub_name,pub_year,unit_price)values(2002,
‘ADBMS’, ‘Bearson’, ‘Pearson’, ‘2004’,550);
Mysql>insert into
book01(isbn,title,author_name,pub_name,pub_year,unit_price)values(2003,
‘FDBMS’ , ‘navatha,’pearson’, ‘2003’,750);
Myqsl> create table author01(authorname varchar(90),country varchar(90));
mysql> insert into author01(authorname,country)values('arora','U.S');
mysql> insert into
author01(authorname,country)values('silberschatz','Asia'); mysql> insert
into author01(authorname,country)values('kapoor','Canada');
mysql> insert into author01(authorname,country)values('Pearson','Germany');
mysql> insert into author01(authorname,country)values('E-navatha','England');
mysql> insert into author01(authorname,country)values('banu','India');
mysql>select *from author01;
Reg No: 912221104006
2. Display the title, author, and publisher name of all books published in 2000,
2002, 2004.
5. Get the details of author who have published book in year 2004.
6. Get the titles of all books written by authors not living in U.S
mysql> select title from book01 where authorname not in(select authorname
from author where country='U.S');
7.Display the titles of books that have price greater than all the books publisher
in year 2004.
Mysql>Savepoint s1;
Reg No: 912221104006
14.Display the student table using select command and observe the
changes.
Mysql>Select * from student_41;
3. Write a query to grant select privilege to a table named “student”, the user name
is “XXX”.
Mysql>GRANT SELECT
>ON student
>TO 'ammu'@'localhost';
Reg No: 912221104006
7. Write a query to revoke delete permission for the ‘student’ table from user name
‘xxxxx’.
Mysql>GRANT SELECT
>ON student
>TO '*'@'localhost';
Mysql>REVOKE ALL
Reg No: 912221104006
>ON student
>FROM ammu;
Reg No: 912221104006
Mysql>desc cust_view;
5. Write a query to create a view cust_view2 from customer table such that
it contains only c_name=’XXX’
CREATE OR REPLACE VIEW cust_view2 AS
SELECT c_name, city
FROM customer
WHERE c_name = 'keerthana';
Reg No: 912221104006
DELIMITER $$
CREATE PROCEDURE User_Variables( )
BEGIN
SET @x=15;
SET @y=10;
SELECT @x,@y,@x-@y;
END$$
mysql> CALL User_Variables( );
-> $$
5. Develop a PL/SQL program to display all records of this table whose marks are
greater than 70 and count all the table rows.
mysql> DELIMITER //
mysql> CREATE PROCEDURE display_marks()
-> BEGIN
-> DECLARE total_rows INT DEFAULT 0;
Reg No: 912221104006
6. Develop a PL/SQL procedure to display only the top 4 rows from studenttable.
mysql> DELIMITER //
mysql> CREATE PROCEDURE display_top_4_students()
-> BEGIN
-> SELECT * FROM student_info
-> ORDER BY marks DESC
-> LIMIT 4;
-> END;
-> //
Reg No: 912221104006
7. Develop a PL/SQL procedure to display the maximum mark from student table.
mysql> DELIMITER //
mysql> CREATE PROCEDURE display_max_mark()
-> BEGIN
-> DECLARE max_mark INT;
-> SELECT MAX(marks) INTO max_mark FROM student;
-> SELECT CONCAT('The maximum mark is ', max_mark) AS result;
-> END //
8. Develop a PL/SQL procedure to get the value from the user and display the
appropriate user mark.
mysql> DELIMITER //
mysql> CREATE PROCEDURE display_user_mark(IN p_stud_id INT)
-> BEGIN
-> DECLARE v_marks INT;
->
-> SELECT marks INTO v_marks FROM student WHERE stud_id = p_stud_id;
->
-> IF v_marks IS NOT NULL THEN
-> SELECT CONCAT('Marks for user with stud_id ', p_stud_id, ': ', v_marks) AS
result;
-> ELSE
-> SELECT CONCAT('No record found for user with stud_id ', p_stud_id) AS result;
-> END IF;
-> END //
Query OK, 0 rows affected (0.02 sec)
mysql> DELIMITER ;
FUNCTIONS:
9. Develop a PL/SQL function that returns the customer occupation based on the
2. Write the PL/SQL to trigger the event before inserting the working hour less than 0.
mysql> DELIMITER $$
mysql> Create Trigger before_inserthour
-> BEFORE INSERT ON employee FOR EACH ROW
-> BEGIN
-> IF NEW.working_hours<0 THEN SET NEW.working_hours=0;
-> END IF;
-> END $$
Reg No: 912221104006
3. Write the PL/SQL to trigger the event after inserting the details
mysql> DELIMITER $$
mysql> Create Trigger after_insert_details2
-> AFTER INSERT ON employee FOR EACH ROW
-> BEGIN
-> INSERT INTO emp_details1 VALUES (NEW.id, NEW.name, NEW.occupation,
NEW.working_hours, CURTIME( ));
-> END$$
Reg No: 912221104006
mysql> DELIMITER $$
mysql> CREATE TRIGGER before_update
-> BEFORE UPDATE ON employee FOR EACH ROW
-> BEGIN
-> DECLARE error_msg VARCHAR(200);
-> SET error_msg=('The working hours cannot be greater than 30');
-> IF new.working_hours>30 THEN
-> SIGNAL SQLSTATE '45000'
-> SET MESSAGE_TEXT=error_msg;
-> END IF;
-> END $$
Reg No: 912221104006
mysql> DELIMITER $$
mysql> CREATE TRIGGER after_delete
-> AFTER DELETE ON empsalary FOR EACH ROW
-> BEGIN
-> UPDATE totalsalary SET total_budget=total_budget-OLD.amount;
-> END $$
Reg No: 912221104006
AIM
To Design XML Schema for the given company database and to implement the following
queries using XQuery.
Requirements:
Notepad
BaseX 7.8.2
Procedure
<?xml version="1.0"?>
<departments>
<department>
<deptName>Research</deptName>
<deptNo>1</deptNo>
<deptMgrSSN>11</deptMgrSSN>
<deptMgrStartDate>1/1/2000</deptMgrStartDate>
<deptLocation>Chennai</deptLocation>
Reg No: 912221104006
</department>
<department>
<deptName>Outsourcing</deptName>
<deptNo>2</deptNo>
<deptMgrSSN>22</deptMgrSSN>
<deptMgrStartDate>1/1/2001</deptMgrStartDate>
<deptLocation>Hyderabad</deptLocation>
</department>
</departments>
//employee.xml
<?xml version="1.0"?>
<employees>
<employee>
<empName>Arthi</empName>
<empSSN>11</empSSN>
<empSex>Female</empSex>
<empSalary>900000</empSalary>
<empBirthDate>1-3-89</empBirthDate>
<empDeptNo>1</empDeptNo>
<empAddress>kknagar,chennai</empAddress>
<empWorksOn>Web Mining</empWorksOn>
</employee>
<employee>
<empName>Malliga</empName>
<empSSN>12</empSSN>
<empSex>Female</empSex>
<empSalary>300000</empSalary>
<empBirthDate>2-3-89</empBirthDate>
<empDeptNo>1</empDeptNo>
Reg No: 912221104006
<empSupSSN>11</empSupSSN>
<empAddress>Anna nagar,chennai</empAddress>
<empWorksOn>Cloud Computing</empWorksOn>
</employee>
<employee>
<empName>Sindharth</empName>
<empSSN>13</empSSN>
<empSex>Male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>4-9-89</empBirthDate>
<empDeptNo>1</empDeptNo>
<empSupSSN>11</empSupSSN>
<empAddress>Anna nagar,chennai</empAddress>
<empWorksOn>Cloud Computing</empWorksOn>
</employee>
<employee>
<empName>Ganesh</empName>
<empSSN>14</empSSN>
<empSex>Male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>6-9-88</empBirthDate>
<empDeptNo>1</empDeptNo>
<empSupSSN>11</empSupSSN>
<empAddress>Anna nagar,chennai</empAddress>
<empWorksOn>Web Mining</empWorksOn>
</employee>
<employee>
<empName>Sruthi</empName>
<empSSN>22</empSSN>
<empSex>Female</empSex>
Reg No: 912221104006
<empSalary>900000</empSalary>
<empBirthDate>3-3-89</empBirthDate>
<empDeptNo>2</empDeptNo>
<empAddress>T nagar,chennai</empAddress>
<empWorksOn>Business Process</empWorksOn>
</employee>
<employee>
<empName>Dhanush</empName>
<empSSN>23</empSSN>
<empSex>Male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>7-9-1992</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>T nagar,chennai</empAddress>
<empWorksOn>Business Process</empWorksOn>
</employee>
<employee>
<empName>Anushya</empName>
<empSSN>24</empSSN>
<empSex>Female</empSex>
<empSalary>400000</empSalary>
<empBirthDate>3-3-90</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>kknagar,chennai</empAddress>
<empWorksOn>Knowledge Process</empWorksOn>
</employee>
<employee>
<empName>Manu</empName>
Reg No: 912221104006
<empSSN>25</empSSN>
<empSex>Female</empSex>
<empSalary>300000</empSalary>
<empBirthDate>3-5-90</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>annanagar,chennai</empAddress>
<empWorksOn>Knowledge Process</empWorksOn>
</employee>
</employees>
//project.xml
<?xml version="1.0"?>
<projects>
<project>
<projName>Web Mining</projName>
<projNo>111</projNo>
<projLoc>Chennai</projLoc>
<projDeptNo>1</projDeptNo>
<projWorkers>
<projWorker>
<name>Manu</name>
<name>Jeyaraman</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>Cloud Computing</projName>
<projNo>112</projNo>
<projLoc>Chennai</projLoc>
Reg No: 912221104006
<projDeptNo>1</projDeptNo>
<projWorkers>
<projWorker>
<name>Arthi</name>
<name>Jeyaraman</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>Business Process</projName>
<projNo>221</projNo>
<projLoc>Chennai</projLoc>
<projDeptNo>2</projDeptNo>
<projWorkers>
<projWorker>
<name>Anushya</name>
<name>J</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>Knowledge Process</projName>
<projNo>222</projNo>
<projLoc>Chennai</projLoc>
<projDeptNo>2</projDeptNo>
<projWorkers>
<projWorker>
<name>Manu</name>
</projWorker>
</projWorkers>
Reg No: 912221104006
</project>
</projects>
XML SCHEMA
department.xsd
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="departments">
<xs:complexType>
<xs:sequence>
<xs:element name="department" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="deptName"/>
<xs:element type="xs:byte" name="deptNo"/>
<xs:element type="xs:byte" name="deptMgrSSN"/>
<xs:element type="xs:string" name="deptMgrStartDate"/>
<xs:element type="xs:string" name="deptLocation"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
employee.xsd
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employees">
<xs:complexType>
Reg No: 912221104006
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="empName"/>
<xs:element type="xs:byte" name="empSSN"/>
<xs:element type="xs:string" name="empSex"/>
<xs:element type="xs:int" name="empSalary"/>
<xs:element type="xs:string" name="empBirthDate"/>
<xs:element type="xs:byte" name="empDeptNo"/>
<xs:element type="xs:byte" name="empSupSSN" minOccurs="0"/>
<xs:element type="xs:string" name="empAddress"/>
<xs:element type="xs:string" name="empWorksOn"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
project.xsd
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="projects">
<xs:complexType>
<xs:sequence>
<xs:element name="project" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="projName"/>
Reg No: 912221104006
Output
<Result>
<dept>
<deptName>Research</deptName>
</dept>
<mgrName>
<empName>Malliga</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Research</deptName>
</dept>
<mgrName>
<empName>Sindharth</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Research</deptName>
Reg No: 912221104006
</dept>
<mgrName>
<empName>Ganesh</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>Dhanush</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>Anushya</empName>
</mgrName>
<mgrSal>
<empSalary>400000</empSalary>
</mgrSal>
</Result>
Reg No: 912221104006
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>Manu</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
2.Retrieve the employee name, supervisor name and employee salary for each employee
who works in the Research Department.
Output
<Result>
<eName>
<empName>Arthi</empName>
</eName>
<supName>
<empName>Arthi</empName>
Reg No: 912221104006
</supName>
<empSal>
<empSalary>900000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>Malliga</empName>
</eName>
<supName>
<empName>Arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>Sindharth</empName>
</eName>
<supName>
<empName>Arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>Ganesh</empName>
Reg No: 912221104006
</eName>
<supName>
<empName>Arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>
3. Retrieve the project name, controlling department name, number of employees and
total hours worked per week on the project for each project.
Output
<Result>
<projName>
<projName>Web Mining</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
Reg No: 912221104006
<projName>
<projName>Cloud Computing</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>Business Process</projName>
</projName>
<depName>
<deptName>Outsourcing</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>Knowledge Process</projName>
</projName>
<depName>
<deptName>Outsourcing</deptName>
</depName>
<workers>1</workers>
</Result>
4. Retrieve the project name, controlling department name, number of employees and total
hours worked per week on the project for each project with more than one employee working
on it.
let $d1 := doc("E:\Durga\XmL\department.xml")
let $d2 := doc("E:\Durga\XmL\project.xml")
Reg No: 912221104006
</depName>
<workers>2</workers>
</Result>
Result
Thus the XML Schema for the given database has been executed and implemented successfully.
Reg No: 912221104006
AIM:
The aim of this experiment is to test the performance of MongoDB when executing CRUD (Create, Read,
Update, and Delete) operations on a single collection, without using any external dataset.
DESCRIPTION:
In this lab experiment, we will use MongoDB to execute CRUD operations on a single collection,
without using any external dataset. We will create a sample schema for the collection and insert a small
amount of data to perform the CRUD operations on.
To perform the CRUD operations, we will use the MongoDB shell, a command-line interface for interacting
with MongoDB. We will execute various queries to create, read, update, and delete data in the MongoDB
CREATE:
To create a new document in MongoDB using the shell, use the insertOne() method as follows:
db.collection.insertOne({field1: value1, field2: value2, ...})
READ:
To read data from a MongoDB collection using the shell, use the find() method as follows:
db.collection.find(query)
UPDATE:
To update an existing document in MongoDB using the shell, use the updateOne() method as
follows:
db.collection.updateOne(filter, update)
DELETE:
To delete a document from a MongoDB collection using the shell, use the deleteOne() method as
follows:
db.collection.deleteOne(filter)
to delete a collection from MongoDB using this shell,use the drop() method as follows:
db.collectionsname.drop()
we will query the data using various filters and criteria. For the Update operation, we will update the data in
the collection. Finally, for the Delete operation, we will remove the data from the collection.
Create database
Create database k7
And use database
Use k7
Queries:
1 .Using the MongoDB shell, create a new document in the "students" collection with the following
attributes:
Name: John Doe
Age: 21
Gender: Male
Major: Computer Science
GPA: 3.8
k7> db.students.insertOne({
name: "John Doe",
age: 21,
gender: "Male",
major: "Computer Science",
gpa: 3.8
})
Reg No: 912221104006
k7>db.students.find()
3 . Using the MongoDB shell, update the document in the "students" collection with the name "John
Doe" to have a GPA of 4.0.
K7> db.students.updateOne(
{ name: "John Doe" },
{ $set: { gpa: 4.0 } }
k7>db.students.find()
Reg No: 912221104006
4 .Using the MongoDB shell, delete the document in the "students" collection with the name "John
Doe".
K7> db.students.deleteOne({ name: "John Doe" })
RESULT
Thus, CRUD operations (create, read, update, delete) on a MongoDB collection was executed
successfully.
Reg No: 912221104006
Aim:
To create Database Design Using ER Modeling, Normalization and Implementation for Any Application
Step 1: Create table using mysqlclient
mysql> use Purchase
Database changed
mysql> create table Customer1(Cid int primary key,Cname varchar(20),Caddress varchar(20),Cphone
int); mysql> create table Order1(Orderid int primary key, Orderdate DATE, Quantity int, Amount int, Cid
int,foreign key(Cid) references Customer1(Cid));
mysql> create table Payments1(Pid int primary key,PaymentDate DATE, Amount int, Cid int,Orderid int,
foreign key(Cid) references Customer1(Cid),foreign key(Orderid) references Order1(Orderid));
Step 6: Select database purchase from the list and press next
Reg No: 912221104006
RESULT
Thus the Database Design Using ER Modeling, Normalization and Implementation for Any Application was
executed successfully.
Reg No: 912221104006
Aim:
To create a student’s database system by establishing MySQL connectivity with
Python as a graphical front-end interface.
Description:
This System focuses on creating a student database system that enables
database connectivity with MySQL using Python. The program provides a user-
friendly front-end interface for interacting with the database. It allows users to
perform essential operations such as inserting data into the database, retrieving
data from the database, updating existing data, and deleting data.
Program:
i) Python code
from tkinter import *
def insert():
id = e_id.get()
name = e_name.get();
Reg No: 912221104006
phone = e_phone.get();
else:
cursor = con.cursor()
cursor.execute("commit");
e_id.delete(0,'end')
e_name.delete(0,'end')
e_phone.delete(0,'end')
show()
con.close();
def delete():
if(e_id.get() == ""):
else:
cursor = con.cursor()
cursor.execute("commit");
e_id.delete(0,'end')
e_name.delete(0,'end')
Reg No: 912221104006
e_phone.delete(0,'end')
show()
con.close();
def update():
id = e_id.get()
name = e_name.get();
phone = e_phone.get();
else:
cursor = con.cursor()
cursor.execute("commit");
e_id.delete(0,'end')
e_name.delete(0,'end')
e_phone.delete(0,'end')
show()
con.close();
def get():
if(e_id.get() == ""):
else:
cursor = con.cursor()
rows = cursor.fetchall()
e_name.insert(0, row[1])
e_phone.insert(0, row[2])
con.close();
def show():
cursor = con.cursor()
rows = cursor.fetchall()
list.delete(0, list.size())
list.insert(list.size()+1, insertData)
con.close()
root = Tk()
root.geometry("600x300");
root.title("Pyhton+Tkinter+MySql")
id.place(x=20,y=50)
name.place(x=20,y=80)
phone.place(x=20,y=110);
e_id = Entry()
e_id.place(x=150, y=50)
e_name = Entry()
e_name.place(x=150, y=80)
e_phone = Entry()
e_phone.place(x=150, y=110)
insert.place(x=20, y=160)
delete.place(x=70, y=160)
update.place(x=130, y=160)
get.place(x=190, y=160)
list = Listbox(root)
list.place(x=320, y=50)
show()
root.mainloop()
Reg No: 912221104006
Create Table
mysql>create table students(id,name,phno);
OUTPUT:
Result:
The provided program demonstrates a student’s database system by
establishing connectivity with MySQL using Python, allowing users to insert,
retrieve, update, and delete data from the MySQL database through a
graphical user interface(GUI).