0% found this document useful (0 votes)
4 views4 pages

Create The Frist Table /: Max MAX

Uploaded by

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

Create The Frist Table /: Max MAX

Uploaded by

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

create database Nekemte_Tvet_college

use Nekemte_Tvet_college
/* create the Frist table */

create table Employee


(
Emp_id char(15) primary key,
E_Fname varchar(50) default 'Adugan',
E_Mname varchar(50) not null,
E_mobno numeric(10))
select*from Employee
select max (salary)from Employee where salary <(select MAX(salary) from
Employee)
select top 3 salary,address,E_Fname from Employee order by salary desc
select distinct top 3 salary,E_Fname from Employee order by salary desc
select E_Fname,salary from employee where(20+salary ) <4000

/* create table second */

create table Customer


(
Cus_id char(15) primary key,
C_Name varchar(15) not null,
C_Lname varchar(40) not null,
C_City char(30),
C_kebele char(40),
C_Sex char(1) default'f' check(C_Sex='f' or C_Sex='m' ))
select*from customer

/* create table Third */

create table Book


(ISBN char(15) primary key,
author varchar(50) not null,
Tittle varchar(50) not null,
Edition varchar(6),
Emp_id char(15) foreign key references Employee (Emp_id) on update cascade on
delete cascade,
Cus_id char(15) foreign key references Customer (Cus_id) on update cascade on
delete cascade)
select* from Book

/* alter table command */


ALTER TABLE employee ALTER COLUMN salary int;

alter table employee add salary varchar(10),age int;


alter table Employee add address varchar(45) not null
alter table Customer add nationality char(20) default 'Ethiopian' not null;
alter table Customer add rentaldate datetime default 17/11/2014 not null;
alter table employee drop column E_mobno;
alter table book alter column ISBN char(8) /* make check */
alter table Customer add Nation varchar(22) default 'Ethopian' not null;
alter table Book add Lammummaa char(15) default 'Ethipian' not null;
alter table Book add region char(15) default 'Oromia' not null;
alter table customer add M_name varchar(14)
alter table employee add unique (E_fname)
/* update command */
update employee set salary=1000,age=20 where emp_id='em01'
update employee set salary=2000, age=15 where emp_id ='em02'
update employee set salary=3000,age =26 where emp_id='em03'
update employee set salary=4000,age =45 where emp_id='em04'
update employee set salary=5000,age =37 where emp_id='em05'
update employee set salary=6000,age =33 where emp_id='em06'
update employee set salary=7000,age =28 where emp_id='em07'
update employee set salary=8500,age =40 where emp_id='em08'
update customer set age=30 where cus_id='cust01'
update customer set age=35 where cus_id='cust02'
update customer set age=39 where cus_id='cust03'
update customer set age=45 where cus_id='cust04'
update customer set age=22 where cus_id='cust05'
update customer set age=15 where cus_id='cust06'
update customer set age=40 where cus_id='cust07'
update customer set age=41 where cus_id='cust08'
update customer set age=19 where cus_id='cust09'
select*from employee
select*from customer
/* insert the frist table */

insert into Employee (Emp_id,E_Fname,E_Mname,address) values


('EM01','Tola','Fufa','Finfinne')
insert into Employee (Emp_id,E_Fname,E_Mname,address) values
('EM02','Tola','Fufa','Finfinne')
insert into Employee values('EM03','Chaltu','Olana','nek')
insert into Employee values('EM04','Dave','Obsa','USA')
insert into Employee values('EM05','Chala','Kenna','nek')
insert into Employee values('EM06','John','Malka','US')
insert into Employee values('EM07','Muller','Guddata','Burayu')
insert into Employee values('EM08','Moan','Jirata','nek')
insert into Employee values('EM09','Tola','Fufa','Finfinne')
insert into Employee (Emp_id,E_Fname,E_Mname,address) values
('EM10','Tola','Fufa','Finfinne')
insert into Employee (Emp_id,E_Fname,E_Mname,address) values
('EM11','Tola','Fufa','Finfinne')

/* insert the second table */

insert into customer values('Cust01','Beekam','Gudina','Ghimbi','G03','m','


',' ')
insert into customer values('Cust02','Amenu','Bonsa','nekemte','nrk07','m','
',' ')
insert into customer values('Cust03','Bikiltu','Jiregn','Bako','Bak01','f','
',' ')
insert into customer values('Cust04','Dame','Darara','Dukam','duk02','m',' ','
')
insert into customer values('Cust05','Seena','Gudina','Dambi','Damb02','f','
',' ')
insert into customer values('Cust06','Mootii','Ayyaana','Haroo','Har03','m','
',' ')
insert into customer
values('Cust07','Nagaasa','Gudina','Burayu','Buray05','m',' ',' ')
insert into customer values('Cust08','Beektu','Guddata','Gidda','G02','f','
',' ')
insert into customer values('Cust09','keenna','Gudina','Shambu','Sham03','m','
',' ')
select *from customer
/* insert the third table */
insert into Book
values('Bk01','Ejigu','Good_Governance','1st','EM05','Cust09',' ',' ')
insert into Book
values('Bk02','Moti','Good_Governance','2st','EM06','Cust05',' ',' ')
insert into Book
values('Bk03','Jirra','Good_Governance','3st','EM04','Cust08',' ',' ')
insert into Book
values('Bk04','Olaana','Good_Governance','4st','EM03','Cust01',' ',' ')
insert into Book
values('Bk05','Gedefa','Good_Governance','5st','EM09','Cust02',' ',' ')
insert into Book
values('Bk06','Tolina','Good_Governance','6st','EM02','Cust03',' ',' ')
insert into Book
values('Bk07','Beeka','Good_Governance','5st','EM01','Cust04',' ',' ')
insert into Book
values('Bk08','Kakuu','Good_Governance','1st','EM08','Cust06',' ',' ')
insert into Book
values('Bk09','Abraam','Good_Governance','7st','EM07','Cust07',' ',' ')
insert into Book
values('Bk10','Abraam','Good_Governance','7st','EM07','Cust07',' ',' ',' ')
select* from book
/*SELECT TABLE COMMAND*/
Select Emp_id,E_Fname from Employee
Select Emp_id,E_Fname from Employee where Emp_id ='EM03'
select Emp_id,E_Fname from Employee Where Emp_id='Em03' or E_Fname='Dave'
select Emp_id,E_Fname from Employee Where Emp_id='Em04' and E_Fname='Dave'
select* from employee order by E_Fname asc
select* from employee order by E_Fname desc
select* from employee where Emp_id ='Em07'
select* from employee where E_FNAME like 'A%'
select* from employee where E_FNAME like '%A'
select* from employee where E_FNAME like 'B%A'
select* from employee where E_FNAME like '%A%'
select* from employee where E_FNAME like '-B' --do your self
select* from employee where E_FNAME like '_Abdi' --do your self
select ISBN,author from book where Emp_id = 'EM01'
select distinct E_FNAME,author from employee,book
select E_FNAME + ' ' + E_Mname as "full name" from employee
select* from Book where author IN('moti','jirra') --do your self
select max (edition) from book

/*modify select command */


select * from employee
select *from customer order by c_name desc
select c_name,c_sex,age, c_city from Customer order by c_name asc ,c_city
desc;
select c_name,sum(age) as total_age from customer group by c_name having
sum(age)>=20 order by sum(age) asc
select emp_id,E_fname,sum(SALARY) from Employee group by emp_id,e_fname
having sum(salary)<=3000 order by sum(salary)
select e_fname,address from employee where not address ='nek'
select e_fname,address,age from employee where address <>'nek' or (age=15 and
e_fname='dave')
select * from Employee where salary between 2000 and 5000
select e_fname,e_mname,salary from employee where salary between 3000 and 6000
select * from employee where e_fname like'c_%_%_%'
select * from employee where e_fname like'_b%'
select min(salary) as smallest_salary from employee where age>=35
select count(salary) as number_salary from employee where age>=30
select sum(salary) from employee
select avg(age) as avg_age from employee where age<=30
select max(salary) as largest_salary from employee
select e_fname,salary from employee where(salary+20 )>3000

select COUNT (*) from Employee


select COUNT (age) from Employee
select COUNT(*),AVG(Employee.salary) from Employee
select STDEV(Employee.Salary) from Employee
backup database Nekemte_Tvet_college to disk ='C:\try\ok\good'

SELECT Book.author, Customer.C_Sex, Employee.E_Fname


FROM Book INNER JOIN
Customer ON Book.Cus_id = Customer.Cus_id INNER JOIN
Employee ON Book.Emp_id = Employee.Emp_id
WHERE (Customer.C_Sex = 'f or') AND (Employee.E_Fname = 'abd' OR
Employee.E_Fname = 'bona')

You might also like