0% found this document useful (0 votes)
7 views7 pages

RDBMS1

The document outlines various SQL commands for creating and manipulating databases related to employees, students, and office management. It includes creating tables, inserting data, performing queries, updating records, and deleting entries across multiple databases. The operations cover employee details, student information, department management, and salary calculations, showcasing a range of SQL functionalities.

Uploaded by

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

RDBMS1

The document outlines various SQL commands for creating and manipulating databases related to employees, students, and office management. It includes creating tables, inserting data, performing queries, updating records, and deleting entries across multiple databases. The operations cover employee details, student information, department management, and salary calculations, showcasing a range of SQL functionalities.

Uploaded by

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

1.

use office
Create table employee_personal_details(employee_id numeric(20) primary key,name
nvarchar(100) not null,
age numeric not null,address nvarchar(25) not null);
create table employee_salary_details(salary_id numeric primary key,employee_id
numeric,salary decimal(10,2) not null,
department nvarchar(10)not null);
insert into employee_personal_details values
('101','guna','19','chennai'),
('102','senthil','20','mumbai'),
('103','rajan','26','northchennai'),
('104','anbu','20','thambaram'),
('105','javaplani','23','perambur'),
('106','chandra','20','banglore'),
('108','mani','20','nandam');
insert into employee_salary_details values
('11','101','20000','201'),
('12','103','22000','202'),
('13','104','26000','202'),
('14','105','40000','204'),
('15','106','35000','205'),
('16','107','30000','206'),
('17','108','31000','202');
select*from employee_personal_details;
select*from employee_salary_details;
select employee_salary_details.employee_id,employee_personal_details.name
from employee_personal_details,employee_salary_details
where employee_personal_details.employee_id=employee_salary_details.employee_id and
employee_salary_details.salary>20000;
select employee_salary_details.department,max(employee_salary_details.salary)as
max_salary from employee_personal_details,employee_salary_details
where employee_personal_details.employee_id=employee_salary_details.employee_id
group by employee_salary_details.department;
select distinct address from employee_personal_details group by address having
count(employee_id)>1;
select department,min(employee_salary_details.salary)as min_salary from
employee_personal_details,employee_salary_details
where employee_personal_details.employee_id=employee_salary_details.employee_id
group by department;
select employee_id,name from employee_personal_details where
employee_salary_details.department is null;

2.create database RDBMS


use RDBMS
CREATE TABLE student_personal_info(roll_no numeric(25) primary key,sname
varchar(25),location varchar(50),phno numeric(20));
create table student_class_info(roll_no numeric(25),sname varchar(25),section
varchar(30));
insert into student_personal_info values
('10','ravi','delhi','9638527410'),
('20','ram','mumbai','9966327410'),
('30','rethi','kolkata','9638512356'),
('40','rasika','lagore','9933312450');
insert into student_class_info values
('10','ravi','A'),
('20','ram','B'),
('30','rethi','C'),
('40','rasika','A');
select*from student_personal_info;
select*from student_class_info;
select student_personal_info.sname,phno from
student_personal_info,student_class_info
where student_personal_info.roll_no=student_class_info.roll_no and
student_class_info.section='A';

3.use RDBMS
create table employee_personal(id numeric(10) primary key,ename
varchar(20),doj varchar(10),age numeric(6),department varchar(25),designation
varchar(10));
insert into employee_personal values
('1','lalitha','23-05-1994','30','IT','HR'),
('2','mahi','26-05-1993','31','sales','TL'),
('3','moni','23-05-2003','21','production','manager'),
('4','kavin','23-05-2002','22','marketing','advisor');
create table employee_salary(id numeric not null,ename varchar(10),salary
numeric(8));
insert into employee_salary values
('1','lalitha','80000'),
('2','mahi','70000'),
('3','moni','60000'),
('4','kavin','50000');
select*from employee_personal;
select*from employee_salary;
update employee_salary set salary=salary*10 from employee_personal,employee_salary
where employee_personal.id=employee_salary.id and employee_personal.age>29;
select*from employee_salary;

4.create database office


use office
create table Dept_table (deptno numeric(20) primary key, dname varchar(20),
location varchar(20));
create table Emp_table(empno numeric not null, ename varchar(20), job varchar(30),
mgr varchar(20), hiredate date, sal numeric(20),
comm numeric(5),deptno numeric(20));
INSERT INTO Dept_table VALUES
(10, 'Accounting', 'New York'),
(20, 'Research', 'Dallas'),
(30, 'Sales', 'Chicago'),
(40, 'Operations', 'Boston');
select*from Dept_table;
insert into emp_table values
(1, 'Ambiga', 'Manager', NULL, '2010-01-15',75000, NULL, 10),
(2, 'Sara', 'Accountant', 1, '2012-03-23', 55000, 5000,10),
(3, 'Seman', 'Clerk', 1, '2015-05-10', 40000, NULL, 10),
(4, 'Abhishek', 'Research Scientist', NULL,'2008-07-30', 80000, NULL, 20),
(5, 'manu', 'Research Assistant', 4, '2014-11-21', 60000,NULL, 20),
(6, 'Arivu', 'Sales Representative', NULL, '2016-12-01',70000, 7000, 30),
(7, 'sita', 'Sales Manager', 6, '2018-06-15', 85000,10000, 30),
(8, 'varshini', 'Operations Manager', NULL, '2005-09-12',90000, NULL, 40),
(9, 'kavitha', 'Operations Assistant', 8, '2011-02-25', 65000,NULL, 40);
select*from emp_table;
update emp_table set sal=sal*15 where datediff(year,hiredate,getdate())>10;
select*from emp_table;
delete from emp_table where datediff(year,hiredate,getdate())>=30;
select mgr, count(*) as num_employee from emp_table where mgr is not null group by
mgr order by num_employee;

5.create database student


use student
create table student (roll_no numeric(20) primary key, Name varchar(50), exam_id
numeric(20) );
create table mark (roll_no numeric(20),exam_id numeric(20), m1 numeric(2),m2
numeric(3),
m3 numeric(4),m4 numeric(5),m5 numeric(3),total numeric(5),average float(9));
insert into student values
('1', 'John','101' ),('2','divya','102'),('3', 'dhran','103'),('4',
'sheela','104'),('5','dharsan','105');
select*from student as s;
insert into mark values('1','101','85','90','78','88','92','433','86.6'),('2',
'102','70','75','80', '85', '90','400','80.0'),
('3', '103','60','62', '58','55','50','285','57.0'),
('4', '104','40','45', '50', '35', '48','218','43.6')
,('5',' 105','65','70', '75',' 80','85','375','75.0');
select*from mark as m;
select s.Name,s.roll_no,s.exam_id,m.m1,m.m2,m.m3,m.m4,m.m5,(m.m1 + m.m2 + m.m3
+m.m4 + m.m5)
AS total,
((m.m1 + m.m2 + m.m3 +m.m4 + m.m5)/5)as average,
case when((m.m1 + m.m2 + m.m3 + m.m4 + m.m5) / 5) >80 then 'Outstanding'
when((m.m1 + m.m2 + m.m3 + m.m4 + m.m5) / 5) >75 then 'First class'
when((m.m1 + m.m2 + m.m3 + m.m4 + m.m5) / 5)between 50 and 60 then 'Second
class'
when((m.m1 + m.m2 + m.m3 + m.m4 + m.m5) / 5) <50 then 'Fail'
else 'No grade'
end as grade from mark as m join student as s On m.Roll_No = s.Roll_No and
m.Exam_ID = s.Exam_ID;

6.create database query


use query
create table employee(emp_no numeric(15) primary key,ename varchar(20),job
varchar(20),salary numeric(10));
alter table employee add doj varchar(10);
insert into employee values
('110','varshini','sales person','10000','27/10/2022'),
('111','varun','manager','40000','24/05/2022'),
('112','vamshi','HR manager','50000','03/12/2023'),
('113','vishal','developer','45000','12/07/2021'),
('114','visag','tester','10000','02/01/2023');
select*from employee;
update employee set job='dev ops' where emp_no='111';
update employee set job='marketing' where emp_no='112';
update employee set job='scrum master' where emp_no='113';
update employee set job='project manager' where emp_no='114';
Exec sp_rename 'employee.salary','emp_salary','column'
delete from employee where emp_no='110';

8.use query
create table dept(deptno numeric(5),deptname varchar(25),dept_location
varchar(25));
alter table dept add designation varchar(25);
insert into dept values
('101','marketing','chennai','manager'),
('102','IT','kerala','HR'),
('103','product intern','delhi','tester'),
('104','data science','kolkata','analyst');
select*from dept;
select deptno,count(*) as no_of_emp from dept group by deptno;
update dept set deptname='product engineer' where deptno='102';
update dept set deptname='resource' where deptno='101';
delete from dept where designation='manager' and deptno='101';

9.use query
create table emp(emp_no numeric(10),emp_name varchar(25),job varchar(20),
basic varchar(20),DA varchar(20),HRA varchar(20),PF varchar(20),gross_pay
varchar(25),
net_pay varchar(25),deptno numeric(20));
insert into emp values
('21','Ram','HR','30000','2000','1500','2000','300','400','201'),
('22','sita','devops','25000','1000','500','300','200','100','202'),
('23','Manju','developer','29000','1300','1000','500','250','100','203'),
('24','Abhi','sales','20000','1400','3000','300','200','100','204'),
('25','deeksh','Manager','30000','2000','1500','2000','300','200','205');
select*from emp;
select emp_no ,emp_name ,basic ,deptno from emp where (Basic,deptno) in (select
min(basic),
deptno from emp group by deptno);
update emp set net_pay=net_pay+1200 where net_pay<10000;
select*from emp where gross_pay between 10000 and 20000;
select*from emp where gross_pay=(select max (gross_pay)from emp);
10.create database coding
use coding
create table Employee(empid numeric(5) primary key,empname varchar(30),salary
numeric(10),deptno numeric(5),
deptname varchar(30),designation varchar(20));
create table Department(deptno varchar(30),deptname varchar(30));
insert into Employee values
('101','Bharath','3000','10','IT','Manager'),
('102','Divya','4000','10','IT','Manager'),
('103','Mirra','5000','10','IT','TL'),
('104','Nithya','6000','10','IT','TL'),
('105','Hema','7000','11','HR','TL'),
('106','Hari','8000','11','HR','TL'),
('107','Soori','9000','12','Sales','Member'),
('108','Meena','10000','12','Sales','Member');
insert into Department values
('10','IT'),('11','HR'),('12','Sales');
select avg(salary) as avg_salary, Employee.designation from Employee where
deptno=10 group by Employee.designation;
select min(salary) as min_salary,deptno from Employee group by deptno;
select count(deptno) as count_deptno,deptno from Employee group by deptno;
select count(Employee.empid) as no_of_emp,Department.deptname
from Employee,Department where Employee.deptno=Department.deptno group by
Department.deptname;
select * from Employee where empname like 'B%' or empname like 'C%';
select empname from Employee where salary >= '5000';

11.use coding
create table emp(empid numeric not null, empname
varchar (20), dept_id numeric(20), jobtype varchar(10),
salary numeric(20), primary key (empid));
insert into emp values
('1', 'mani', '10', 'manager', '5000'),
('2','ram', '20', 'clerk', '2500'),
('3', 'kası', '20', 'clerk', '2700'),
('4', 'dany', '30', 'analyst', '4000'),
('5', 'jeeva', '20', 'clerk', '3000'),
('6', 'John', '10', 'analyst', '3600');
select*from emp;
select*from emp count where dept_id=20;
select MIN (salary) as min_salary from emp where jobtype='clerk';
select MIN (salary) as min_salary, MAX (salary) as max_average, AVG (salary) as
avg_salary from emp;
select jobtype, MIN (salary) as min_salary, MAX(salary) as max_salary from emp
group by jobtype;
select empname from emp order by empname desc;
select empid, empname from emp order by empid asc;

12.use coding
create table office (office_id numeric not null,name varchar(25),salary
numeric(10),dept_no numeric(10),
manager_id numeric not null);
insert into office values
('1','deepi',' 5000', '10','101'),
('2','manju','6000','10','101'),
('3', 'kav', '7000','20','102'),
('4','jan','8000','30','102');
select concat(substring(name,1,4),substring(name,2,3))as combined_name from office;
select name,salary,(salary*1.15) as increased_salary from office;
select manager_id ,min(salary) as min_salary from office group by manager_id;
select dept_no,AVG(salary)as avg_salary from office group by dept_no;
select dept_no,avg(salary)as avg_salary from office group by dept_no having
(count(office_id))=2;
select office_id,AVG(salary)as avg_salary from office group by office_id;

13.use coding
create table Branch (Branch_name varchar(20),Branch_city varchar(20), Assets
numeric(30));
ALTER TABLE Branch alter column Assets numeric(10);
Alter table Branch add Branch_mail varchar(20);
Alter table Branch drop column Branch_city;
insert into Branch values
('branch A','100000','[email protected]'),
('branch B','750000','[email protected]'),
('branch C','200000','[email protected]');
update Branch set Branch_name='Ani' where Branch_name='branch A';
update Branch set Branch_name='Abhi' where Branch_name='branch B';
update Branch set Branch_name='Gayu' where Branch_name='branch C';
select *from Branch;
Alter table Branch drop column Branch_mail;
Alter table Branch drop column Assets;
select *from Branch;

14.use RDBMS
create table stock(sid numeric(20)NOT NULL,sname varchar(20),rating varchar(20));
alter table stock Add age numeric(10);
select * from stock;
insert into stock values
('101','Ani','8','20'),
('102','Ravi','9','20'),
('103','Sita','7','22'),
('104','diva','8','30'),
('105','aswitha','7','27');
select * from stock;
delete from stock where rating > 8;
update stock set age = '30' where sid='103';
update stock set age='24' where sid='101';
update stock set age=null where sid='103';
update stock set age='25' where sid='105';
insert into stock values
('106','Muthu','null','19'),
('107','Saro','null','18');
select*from stock;

15.use rdbms
create table customer(customer_name varchar(20),customer_street
varchar(20),customer_city varchar(20));
insert into customer values
('hari','annanagar','chennai'),
('kayal','anna ','new york'),
('viji','mainroad','kerala');
alter table customer add salary numeric(10);
alter table customer alter column salary numeric(20);
alter table customer drop column salary;
delete from customer where customer_city='new york';
select*from customer;

You might also like