Doc1 2
Doc1 2
Sankhamul, Lalitpur
Affiliated to Tribhuwan University
Keywords:DBMS,SQL,DDL,ER-Data Model,etc.
Abstract
This project aims to harness MySQL for creating ,modifying,and
retrieving data in databases,providing a comprehensive guide to
database management.It covers syntax,queries and outcomes,offering
clear solutions for various tasks.Additionally,it explores techniques like
altering,dropping,and truncating databases,as well as Iaddresses SQL
constraints such as NOT NULL,UNIQUE,PRIMARY KEY,FOREIGN
KEY,CHECK,and DEFAULT constraints.It demonstrates the creation of
virtual tables,data display using pattern matching with the LIKE clause,
and the use of joins like Natural join and various types of Outer
join.Furthermore,it showcases the application of operators like
IN,NOT,BETWEEN,and NOT BETWEEN,making it a valuable resource for
mastering MySQL queries.
Acknowledgement
I want to thank Mr.Mohan Singh Ayer,my teacher,for his amazing
guidance.His support and encouragement were crucial for me to finish
the assignment. I'm also grateful for his help in proofreading and
correcting my mistakes.I feel lucky to have had his consistent support.
I'm thankful to my friends for helping with the project.And to the college
staff for creating a supportive environment.Thanks to everyone who
assisted me along the way.
Table of contents
Abstract
Acknowledgement
Introduction
References
Introduction
Result:
Solution:
(
Did int(10)primary key,
Dname varchar(100),
Sid int,
);
Result:
Solution:
Syntax:Desc table_name;
Result;
Result;
LAB 2.
Q.N.6. Delete table employee from your database
Solution;
Result;
Insert into
employee(eid,ename,address,phone)values(102,'sarah','Nakhu',9843882346);
insert into
employee(eid,ename,address,phone)values(103,'alan','baudha',9867543568)
insert into
employee(eid,ename,address,phone)values(104,'tika','bhaktapur',9849399039)
Insert into
employee(eid,ename,address,phone)values(105,'kiran','bhaktapur',9745957123);
Result:
Q.N.8. Write a query to delete all employee record who are from Bhaktapur.
Solution:
Syntax; delete from <table_name>where address=' ';
Query: delete from employee where address= 'Bhaktapur';
Result;
Solution:
Syntax; update table<table_name>set<new_name>where column_name=column id;
Query: update student set address='kathmandu' where sid=2;
Q.N.11. Delete student's name from table student whose id is 1.
Syntax;delete from <table_name>where column_name=id;
Query: delete from student where sid=1;
Result:
Q.N.13. Print or display employee's name from employee table who are working in IT
department.
Solution;
Syntax; select column name from table 1 join table 2 on
table1.column_name=2.column_name;
Result;
Q.N.14. Write a query to create table department where fid is working as a foreign
key.
Solution;
Foreign
key<column1_name>references<primary_key_table_name(primary_key_column_na
me)
);
-> (
-> );
Result:
Q.N.15. Write a query which will increase the salary of each department by Rs 1000
Solution:
Syntax;update<table_name>set<column_name>=column+<value>;
Query : update employee set salary=salary + 1000;
Result:
LAB 3.
Result;
Result:
Q.N.19. Write a query to select name, address and salary of all employees whose
department id is 2002
Solution;
Result:
Q.N.20. Create table student where all fields should be not null.
Solution:
Syntax;Create table<table_name>
(
<column1><datatype>not NULL,
<column2><datatype>not NULL,
);
Syntax;Create table<table_name>
(
<column1><datatype>UNIQUE,
<column2><datatype>UNIQUE,
);
Q.N.23. Create table customer and Orders and orders table should have foreign key.
Solution;
Query:
create table customers
-> (
-> cusid int(2) primary key
-> );
: create table orders
-> (
-> oid int(2) NOT NULL,
-> fooditem varchar(50),
-> foreign key(oid) references customers(cusid)
-> );
Result:
Solution:
<column1><datatype>,
<column2><datatype>,
CHECK(column1>0)
);
-> CHECK(atmid>0)
-> );
Result
Solution:
<column1><datatype>default value,
<column2><datatype>default value
);
-> );
Result:
LAB 4
Q.26. Write a SQL query to retrieve empno, ename, job,salary of all employees in
descending order of their salary.
Solution;
Result:
Q.27. Write a SQL query to retrieve all information of employee that belongs to
department number 10 or 20.
Solution:
Syntax: Select all from <table1_name>join<table2_name>on
primary_key_table_name.column1_name>=<foreign_key_table_name.column1_nam
e>where table2 column2_name=value1 OR value2;
Result:
Q.28. Write a query in SQL to list the employee who does not belongs department no
10.
Sollution;
Query;
Result:
Q.29. Write a SQL query to retrieve employee information whose salary is greater
than average salary of all employee.
Solution;
Result:
Q.30Write a SQL query to display all employee who does not have any commission.
Solution;
Result:
Q.31. Display empname and annual total salary of individual’s employee from
employee table.
Solution;
Result:
Q.32. Write a SQL query to display department number and total salary of each
department (use group by clause).
Solution;
Result:
Q.33. Write a SQL query to display information of employee whose name starts with
A.
Solution;
Result:
Q.34. Write a SQL query to find out total number of department in the given
employee table
Solution:
Query:
Result:
Q.35. Display all the information of employee whose salary is between 3000 AND
5000.
Solution:
Query: select * from employees where salary BETWEEN 3000 AND 5000;
Result:
LAB 5
Solution:
Result:
Solution:
Result:
Solution:
Result:
Solution;
Result:
Solution:
Result:
Q.41. Display branch and total marks of individual department from student table
using group by clause.
Solution:
Result:
Q.42. Display branch and total marks of IT branch only from student table.
Solution:
Result:
Solution:
Solution:
Result
Q.45. Write a query to display employee in which city name starts with ‘ka’ ends with
‘ti’ and contains multiple character between ‘ka’ and ‘ti’.
Solution:
Query:
Result:
LAB 6
Q.46. To find employee name containing exactly 5 characters use 5 instances of the
_pattern character.
Solution:
Result:
Q.47. Display all the records from left table with matched records from right table.
There are two tables given to you as employee and department.
Solution:
Q.48. Display employee name and department name from employee and department
table using natural join.
Solution:
Result:
Solution:
Result:
Q.50. Write a query for adding empno in emp table at first row of the table
Solution:
Syntax:alter table<table_name>add column name<datatype>first;
Result:
Q.51. Write a query to display marks details in which marks starts with 4.
Solution:
Result:
Q.52. Write a query to display employee details in which name contains letter ‘ik’ in
between.
Solution:
Result:
Solution:
Result:
Q.54. Display all employees with the salary except between 4000 to 5000.
Solution:
Syntax:Select all from <Table_name>where column_name NOT BETWEEN value AND value;
Query: select * from employee where salary NOT BETWEEN 4000 and 5000;
Resullt:
Q.55. Select all records from employee table where job is not manager.
Solution:
Result:
References: