The document outlines the creation of a database schema with tables for Department, Employee, Project, Dependent, Work_on, and Dept_location, including their relationships and constraints. It includes SQL commands for creating tables, altering them to add foreign keys, and inserting sample data into the Employee and Department tables. Additionally, it demonstrates various SQL queries for retrieving and manipulating date-related information from the Employee table.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views
date function
The document outlines the creation of a database schema with tables for Department, Employee, Project, Dependent, Work_on, and Dept_location, including their relationships and constraints. It includes SQL commands for creating tables, altering them to add foreign keys, and inserting sample data into the Employee and Department tables. Additionally, it demonstrates various SQL queries for retrieving and manipulating date-related information from the Employee table.
insert into Employee values('ESSN 01','Solomon','Abebe','m','Adama',5000,'12- 5-1985',null) insert into Employee values('ESSN 02','Abel','Tadesse','m','Addis Abeba',2500,'01-28-1950',null) insert into Employee values('ESSN 03','Mikyas','Derebe','m','Jigijiga',11000,'07-12-1979',null) insert into Employee values('ESSN 04','Helen','Hagos','f','Mekele',12280,'08- 30-1981',null) insert into Employee values('ESSN 05','Biniam','Tafesse','m','Hawassa',8000,'02-25-1978',null) insert into Employee values('ESSN 06','Samrawit','Alemu','f','Bahirdar',15000,'11-13-1969',null) insert into Employee values('ESSN 07','Gizaw','Nida','m','Axum',10000,'11-11- 1980',null)
select GETDATE() 'current date'
select Fname +' '+ Lname 'full name' ,DATEPART(YY ,Bdate)'year',DATEPART(mm,Bdate)'month',DATEPART (dd,Bdate)'date' from Employee select DATEADD (DAY,45,Bdate)'birth date' from Employee where ESSN ='ESSN 01' select dateadd (month,1,Bdate) from employee where ESSN='ESSN 01' select DATEADD (year,1,Bdate) from Employee where ESSN ='ESSN 01' select DATEDIFF(YEAR ,'1980-11-11','1985-12-05') 'year diff' Select Fname from Employee where sex='m' and DATEDIFF(YEAR,Bdate,GETDATE ())>50
insert into Department values('D01','ICT','ESSN 01','2008-05-15')
insert into Department values('D02','Marketing','ESSN 02','2009-07-29') insert into Department values('D03','Finance','ESSN 06','2011-08-07') insert into Department values('D04','Administration','ESSN 04','1995-05-12') insert into Department values('D05','Researching','ESSN 05','1995-05-12')