Coll & Clus
Coll & Clus
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
-- 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
-- aggagative function
--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
/*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’
*/
------- 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