0% found this document useful (0 votes)
38 views3 pages

Dbs Lab 1

The document describes steps to create a simple employee database in SQL including: 1) Creating a database named "EmployeeDB" and table named "Employees" with columns like ID, name, date of birth etc. 2) Inserting at least 5 sample records into the "Employees" table. 3) Writing SQL queries to display, filter, sort, update, delete data and perform calculations on the employee records.

Uploaded by

Haadi Khan
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)
38 views3 pages

Dbs Lab 1

The document describes steps to create a simple employee database in SQL including: 1) Creating a database named "EmployeeDB" and table named "Employees" with columns like ID, name, date of birth etc. 2) Inserting at least 5 sample records into the "Employees" table. 3) Writing SQL queries to display, filter, sort, update, delete data and perform calculations on the employee records.

Uploaded by

Haadi Khan
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/ 3

Task: Create a simple employee database.

● Create a new database named "EmployeeDB".

Ans) - - creation of database


create database "EmployeeDB"

● Create a table named "Employees" with the following columns:

1. Employee ID (auto-incremented integer, primary key)


2. First Name (text)
3. Last Name (text)
4. Date of Birth (date)
5. Gender (text)
6. Department (text)

Ans) - - creation of table


create table "Employees"(Id int ,
EmployeeID nvarchar (100) ,
FirstName nvarchar (100) ,
LastName nvarchar (100) ,
DateofBirth date ,
Gender nvarchar(100) ,
Department nvarchar(100))

● Insert at least 5 sample records into the "Employees" table.

Ans) - - insert into


insert into "Employees" values (1, 156730 , 'Rehan', 'Malik', '16Feb1990' , 'Male' , 'SE')
insert into "Employees" values (2, 156731 , 'Rohan', 'Khan', '15Aug1999' , 'Male' , 'CS')
insert into "Employees" values (3, 156732 , 'Abdul', 'Haadi', '23Dec2000' , 'Male' , 'Sales')
insert into "Employees" values (4, 156733 , 'Ayesha', 'Noor', '06Oct1989' , 'Female' , 'BBA')
insert into "Employees" values (5, 156734 , 'Fatima', 'farooq', '10Jan2001' , 'Female' , 'MS')

● Write an SQL query to display all employees information.

Ans) - - select
select * from "Employees"
● Write an SQL query to display the employees who belong to the
"Sales" department.

Ans) - - select
select * from "Employees" where 'Sales' = Department

● Write an SQL query to display the employees information sorted by


their last names in ascending order.

Ans) - - select
select * from "Employees" ORDER BY LastName ASC

● Write an SQL query to update the department of an employee with a


specific Employee ID.

Ans) - - updation of record in database


UPDATE "Employees"
SET Department = 'IT'
WHERE EmployeeID = 156731

● Write an SQL query to delete an employee with a specific Employee


ID.

Ans) - - - SQL delete statement


DELETE FROM "Employees"
WHERE EmployeeID = 156734

● Write an SQL query to calculate the average age of all employees.

Ans) - - select
select avg (datediff (year,Dateofbirth,getdate())) from "Employees"

● Write an SQL query to create a new table named "Salary" with the
following columns:

1. Employee ID (integer)
2. Salary (float)

Ans) - - creation of table


create table "Salary"(Id int , EmployeeID nvarchar (100) , Salary nvarchar (100))

You might also like