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

Coll & Clus

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)
6 views3 pages

Coll & Clus

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

CREATE DATABASE Permission

USE permission
create table persons(sid char(55)primary key,Fname char(88),Lname char(89),sex
char(10))
insert into persons values('s01','Abdi','Begna','M')
insert into persons values('s02','chaltu','kuma','F')
insert into persons values('s03','bekele','hika','m')
alter table persons add salary numeric
select * from persons
select * from Employee
select * from Employee where E_Fname in('abdi','John')
select * from Employee where E_Fname in (select Fname from persons )
update Employee set salary =2000 where E_Fname in (select sid from persons
where Fname ='abdi') --null

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),sid char(55) foreign key references persons(sid)on delete
CASCADE on update CASCADE)
alter table employee add salary numeric
alter table employee drop column salary
insert into Employee values('EM03','Chaltu','Olana',0918333894,'s01')
insert into Employee values('EM04','Dave','Obsa',091833389,'s02')
insert into Employee values('EM05','Chala','Kenna',0918333894,'s03')
insert into Employee values('EM06','John','Malka',0918333894,'s03')
insert into Employee values('EM07','Muller','Guddata',0918333894,'s03')
select*from Employee
select*from persons
select sid from persons where sid =(select E_Fname from Employee where sid
='s01')
select E_Fname from Employee where sid =( select sid from persons where
name='abdi')

--select eid,ename,salary from employe where did=(select did from department


where dname='finance')
--update
update employee set salary=3000 where emp_id='em03'
update employee set salary=4000 where emp_id='em04'
update employee set salary=5000 where emp_id='em05'
update employee set salary=6000 where emp_id='em06'
update employee set salary=7000 where emp_id='em07'
-- Comparision expression
select salary,age from Employee where salary<>2000 and age =33
select salary from Employee where salary not between 2000 and 3000
select salary from Employee where salary=2000
select salary from Employee where not salary=2000
select salary from Employee where salary<>2000
select * from Employee where age in (11,33)
--Boolean expression and , or ,not
select salary ,age from Employee where salary =2000 or age =33
select salary from Employee where salary =2000 and age =33
select * ,salary,sex from Employee,persons where salary =2000 and sex='f'
select E_Fname,E_Mname from Employee where E_Fname='Abdi' or E_Fname= 'dave'
and age=11

-- arithmetical +,*,%,/,-
SELECT *, salary= salary*20/100 FROM Employee where salary <3000 -- add
percent
select (100+Salary)*20 from EMPLOYEE
SELECT salary-100 AS TOTAL_SAL FROM Employee where salary >3000
SELECT salary*100 AS TOTAL_SAL FROM Employee where salary >3000
SELECT salary/100 AS TOTAL_SAL FROM Employee where salary >3000
SELECT salary%100 AS TOTAL_SAL FROM Employee where salary >3000
SELECT Emp_id, E_Fname ,salary+100 FROM Employee WHERE salary <3000

Select salary, (salary+100) ,(salary+1000),(salary+5000) from EMPLOYEE


select Emp_id 'identifier',E_Fname 'first name' from Employee;
--update values
UPDATE Employee SET Salary = 1000 where salary=600
UPDATE Employee SET Salary = Salary + Salary * 20/100 where salary=1000
update persons set salary=3500 from persons where sid ='s03'
UPDATE Employee SET E_mobno = 091954655 , E_Fname='Abdi' where Emp_id='EM03'
sp_RENAME 'sell_persons','Employee'
select E_Fname,Emp_id into person from EMPLOYEE where Emp_id='EM03';

-- aggagative function

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, Fname, COUNT (*) FROM persons, EMPLOYEE


WHERE sex= 'm' AND age<40
GROUP BY E_Fname, Fname HAVING COUNT (*) <5;

select COUNT(*),avg(salary)from Employee


select MAX(Salary) from Employee
select fname,COUNT(salary) from persons group by Fname, lname
select COUNT(*), AVG(Employee.Salary) from dbo. Employee
select COUNT(distinct salary) from employee
select SUM(salary) as
sum_salary,MIN(salary),MAX(salary),AVG(salary),COUNT(salary) from Employee
select top 3 salary,E_Mname,E_Fname from Employee order by salary desc
select E_Fname, Lname,SUM(age)as sum_of_age from Employee,persons group by
E_Fname,Lname
select top 3 Emp_id,max(age)from Employee group by Emp_id

--JOINS
SELECT E_Fname FROM Employee UNION SELECT Fname FROM persons
SELECT E_Fname from EMPLOYEE INTERSECT SELECT Fname FROM persons
SELECT * from EMPLOYEE
crossjoin
SELECT * FROM persons
SELECT Employee.*, persons.*
FROM Employee INNER JOIN
person ON Employee.Emp_id = person.Emp_id, persons

create login S02 with password ='abdik' ,default_database = permission;


create login S01 with password ='abdik' ,default_database = permission;
create user abdi for login s01
create user chala for login s02
grant select on employee to abdi with grant option
grant select on employee to chala with grant option
revoke grant option for select on employee from abdi cascade
revoke select on employee from abdi

create role abdi


grant select on permission to abdi
create login persons with password ='abdik'

/*second
CREATE USER <new user name> FOR LOGIN <login name>
Example: CREATE USER Admin1 for login Student
*/
/* frist
CREATE LOGIN [login_Name] WITH PASSWORD = 'password'
Example: CREATE LOGIN student WITH PASSWORD=’abc/123’
*/

create role s01

select * from Employee


select * from persons

select max(salary) from Employee,persons

------- Login
create login Ab with password ='ab@12'
create login ABc with password='abc@123'
create user Galana for login ABc
create user kura for login Ab
grant select,insert on Employee to Galana
revoke select,insert on Employee from Galana
create role DBA
sp_addrolemember'DBA',Galana
sp_addrolemember'DBA',kura
grant select,update on Employee to DBA
revoke select,update on employee to DBA

select Emp_id,len(Fname) from Employee ,persons where Emp_id ='em05'

select * from Employee


select * from persons

You might also like