Você está na página 1de 3

1.

Implementação da base de dados HOTEL no SQL

 IMPLEMENTACAO DA BASE DE DADOS HOTEL


create database hotel;
use hotel;

create table cliente(num_BI varchar(13) not null PRIMARY KEY, nome varchar(50) not
null, sexo varchar(10) not null, telefone varchar(20) null);

create table servico (id_servico int not null primary key, descricao text not null,
valor float not null);

create table tipo_quarto(id_tipo varchar(20) not null primary key, descricao text
not null, valor float not null);

create table quarto(num_quarto int not null primary key, andar int null, id_tipo
varchar(20) not null foreign key(id_tipo) references tipo_quarto(id_tipo), status_
text not null);

create table reserva(id_reserva int not null primary key, num_BI varchar(13) foreign
key(num_BI) references cliente(num_BI), num_quarto int foreign key(num_quarto)
references quarto(num_quarto), dt_reserva date not null, qtd_dias int not null,
data_entrada date not null, status_ text not null);

create table hospedagem(id_hospedagem int not null primary key, num_BI varchar(13)
foreign key(num_BI) references cliente(num_BI), num_quarto int foreign
key(num_quarto) references quarto(num_quarto), data_entrada date not null,
data_saida date null, status_ text not null);

create table atendimento(id_atendimento int not null primary key, id_servico int
foreign key(id_servico) references servico(id_servico), id_hospedagem int foreign
key(id_hospedagem) references hospedagem(id_hospedagem));

2. Criando utilizadores com os papeis de gerente, atendente, estagiario:

 Gerente
USE [master]
GO
CREATE LOGIN [loginGerente] WITH PASSWORD=N'', DEFAULT_DATABASE=[hotel],
CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [hotel]
GO
CREATE USER [_Gerente] FOR LOGIN [loginGerente]
GO

 atendente
USE [master]
GO
CREATE LOGIN [loginAtendente] WITH PASSWORD=N'', DEFAULT_DATABASE=[hotel],
CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [hotel]
GO
CREATE USER [atendente] FOR LOGIN [loginAtendente]
GO

 atendente
USE [master]
GO
CREATE LOGIN [loginEstagiario] WITH PASSWORD=N'', DEFAULT_DATABASE=[hotel],
CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [hotel]
GO
CREATE USER [estagiario] FOR LOGIN [loginEstagiario]
GO

3. Conceder permissão para o gerente acessar todas as tabelas e conceder


Permissões para outros utilizadores.
USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_accessadmin] TO [_Gerente]
GO
USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO [_Gerente]
GO
USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_datawriter] TO [_Gerente]
GO
USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_ddladmin] TO [_Gerente]
GO
USE [hotel]
GO
ALTER ROLE [db_accessadmin] ADD MEMBER [_Gerente]
GO
USE [hotel]
GO
ALTER ROLE [db_datareader] ADD MEMBER [_Gerente]
GO
USE [hotel]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [_Gerente]
GO
USE [hotel]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [_Gerente]
GO

4. Conceda a permissão para o tendente adicionar reservas e pedidos.


USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_datawriter] TO [atendente]
GO
USE [hotel]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [atendente]
GO

5. Conceda a permissão para o estagiário acessar a ListaCliente


USE [hotel]
GO
ALTER AUTHORIZATION ON SCHEMA::[db_datareader] TO [estagiario]
GO
USE [hotel]
GO
ALTER ROLE [db_datareader] ADD MEMBER [estagiario]
GO

Você também pode gostar