0% found this document useful (0 votes)
19 views

Create Database Coolege

The document creates a college database and emp and dept tables. It inserts sample data and runs select queries. It then creates logins and users, an admin role, and grants/denies permissions to users on the emp table and a view.

Uploaded by

bisrat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Create Database Coolege

The document creates a college database and emp and dept tables. It inserts sample data and runs select queries. It then creates logins and users, an admin role, and grants/denies permissions to users on the emp table and a view.

Uploaded by

bisrat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

create database coolege;

use coolege;

create table emp(empid int primary key,fname varchar(20),age int,salary int)

create table dept(did int primary key,empid int foreign key references
emp(empid), dname varchar(20))

insert into emp values(1,'ayle',23,2000)


insert into emp values(2,'belete',33,3000)
insert into emp values(3,'aster',43,6000)
insert into emp values(4,'abebe',28,4000)

insert into dept values(1,1,'IT')


insert into dept values(2,2,'HR')
insert into dept values(3,2,'FINANCE')
insert into dept values(4,3,'DIRECTOR')

select * from emp


select * from dept
--1 create login
create login A5 with password='123'

create login A6 with password='456'

--2 create users


create user fekadu for login A5
create user tafere for login A6

--3 create roles

create role admin

--4 add users to role


sp_addrolemember 'admin',fekadu
sp_addrolemember 'admin',tafere

--5 database grant deny revoke


grant insert,select,update(fname)on emp to fekadu with grant option
grant insert on emp to tafere
deny update on emp to tafere

create view empview1 as select fname,age,salary from emp where salary >=2000

select * from empview1

You might also like