SQL Final
SQL Final
Ans –
CREATE TABLE employee(
S.No. int,
Name varchar(30),
Designation varchar(30),
Branch varchar(30),
);
Ans –
CREATE TABLE Bank_details(
S.No. int,
Cust.Name varchar(30),
AccNo int(30),
Balance int(20),
CustBranch varchar(30),
);
SQL query:
SELECT city, latitude, temperature
*FROM START
WHERE month = 7
ORDER BY temperature ASC, city ASC, latitude ASC;
Output –
Id City Latitude Month Temperature
04 Mainpat 114 20 July 20
01 Kondagaon 111 05 July 32
05 Jashpur 115 25 July 38
02 Raipur 112 10 July 45
03 Janjgir 113 15 July 52
. Q5. Create a check constraint that MONTH should between 1 and 12 ?
Ans. –
Assume we have alredy created a table, named ‘Month’ and their values are –
mid month
01 January
02 Febuary
03 March
04 April
05 May
Note- This statement adds a check constraint to the table that ensures that the
"month" column can only contain values between 1 and 12.
Q6. Write a query in sql to create a table employee and department.
Employee(empno, ename, deptno, job, hiredate)
Department(deptno, dname, loc) ?
Ans –
CREATE TABLE Employee(
empno. int,
ename varchar(30),
deptno int(30),
job varchar(30),
hiredate varchar(30),
);
Ans –
CREATE TABLE emp(
EMPNO int,
ENAME varchar(30),
JOB varchar(30),
MGR varchar(30),
HIREDATE varchar(30),
SAL int(20),
COMM int(20),
DEPTNO int(20),
);
INSERT INTO emp (EMPNO , ENAME, JOB, MGR, HIREDATE, SAL, COMM,
DEPTNO)
VALUES (7369,' SMITH ', ‘CLERK’ , 7902, ‘17-DEC-80’ , 800 , , 20 );
INSERT INTO emp (EMPNO , ENAME, JOB, MGR, HIREDATE, SAL, COMM,
DEPTNO)
VALUES (7499,' ALLEN ', ‘SALESMAN, 7698, ‘20-FEB-81’ , 1600, 300 , 30 );
INSERT INTO emp (EMPNO , ENAME, JOB, MGR, HIREDATE, SAL, COMM,
DEPTNO)
VALUES (7521,' WARD ', ‘SALESMAN, 7698, ‘22-FEB-81’ , 1250, 500 , 30 );
INSERT INTO emp (EMPNO , ENAME, JOB, MGR, HIREDATE, SAL, COMM,
DEPTNO)
VALUES (7566,' JONES ', ‘MANAGER, 839, ‘02-APR-81’ , 2975, , 20);
INSERT INTO emp (EMPNO , ENAME, JOB, MGR, HIREDATE, SAL, COMM,
DEPTNO)
VALUES (7654,' MARTIN ', ‘SALESMAN, 7698, ‘28-SEP-81’ , 1250, 1400 , 30);
Q8. Add a new column in your table : AGE ? in employee table.
Ans –
Assume we have alredy created a table, named ‘emp’ and their values are –
E.id Ename Address Salary
01 Sanjay Raipur 50000
02 Rahul Delhi 30000
03 Vikas Mumbai 45000
04 Priya Kondagaon 40000
05 Neha Jaipur 35000
Query -
Select * from (select * from emp order by Paid_Salary desc) Where
rownum<=5);
Output –
E.id Ename Paid_Salary
01 Rohan 50000
03 Mohan 45000
04 Neha 31000
02 Sohan 30000
06 Vinay 25000
Q10. Drop table department?
Ans –
Assume we have alredy created a table, named ‘department’ and their values
are –
d.id dname FacultyName Salary
01 Maths Mohan 50000
02 Physics Rohit 30000
03 CS Sohan 45000
04 Machenics Rishbh 40000
05 Descrete Harsh 35000