SQL Server: Kasutajad ja õigused

Andmebaasi loomine

Tabelite loomine

create table movies(
ID int identity(1,1), 
moviesNimi varchar(50),
moviesYear int,
movieDir VARCHAR(50),
movieCost int
);
create table guest (
ID int identity(1,1),
name VARCHAR(50)
);

Tabelite täiendamine

INSERT INTO movies (moviesNimi, moviesYear, movieDir, movieCost) VALUES
('Inception', 2010, 'Christopher Nolan', 160000000),
('The Matrix', 1999, 'The Wachowskis', 63000000),
('Interstellar', 2014, 'Christopher Nolan', 165000000),
('The Godfather', 1972, 'Francis Ford Coppola', 6000000),
('The Dark Knight', 2008, 'Christopher Nolan', 185000000),
('Pulp Fiction', 1994, 'Quentin Tarantino', 8000000),
('Fight Club', 1999, 'David Fincher', 63000000);


INSERT INTO guest (name) VALUES
('John Doe'),
('Jane Smith'),
('Alice Johnson'),
('Bob Brown'),
('Charlie Davis'),
('Eve Martin'),
('Frank White');

Kasutajate loomine

Annan kasutajale õigused ja piiranguid

grant select, insert ON guest TO "DirectorNimi";

grant update on movies (MovieCost, MovieDir) to "DirectorNimi";

grant Select on movies (MovieCost, MovieDir) to "DirectorNimi";

Kontroll

Select  MovieCost, MovieDir From movies 
REVOKE INSERT ON guest FROM "DirectorNimi";
insert into guest (name) VALUES ('Lev Egorov');

Lisa kommentaar