0% found this document useful (0 votes)
53 views6 pages

Diagram A

The document contains the SQL scripts to create tables, functions, and a trigger for a hotel database. The tables created include services, rooms, guests, reservations, service details, customers, and reservation-customer details. Functions are created to get the first letter of a string, first word, last letter, and count vowels. A trigger is created to generate login credentials for guests upon insertion into the guests table by calling the functions.

Uploaded by

Jorge Arcadio
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)
53 views6 pages

Diagram A

The document contains the SQL scripts to create tables, functions, and a trigger for a hotel database. The tables created include services, rooms, guests, reservations, service details, customers, and reservation-customer details. Functions are created to get the first letter of a string, first word, last letter, and count vowels. A trigger is created to generate login credentials for guests upon insertion into the guests table by calling the functions.

Uploaded by

Jorge Arcadio
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/ 6

SOLUCION DE DBA HOTEL LAS FLORES

 SCRIP DE LAS TABLAS SQL, VALORES POR DEFECTO

CREATE TABLE servicio_adicional


(
id_sa int NOT NULL,
tipo_servicio varchar(30),
precio varchar(30),
descripcion varchar(30),
CONSTRAINT PK_servicio_adicional PRIMARY KEY (id_sa)
)
go

drop table habitacion


CREATE TABLE habitacion
(
numero int NOT NULL,
tipo_habitacion varchar(30),
estado varchar(30),
codigo varchar(30),
precio varchar(30),
CONSTRAINT PK_habitacion PRIMARY KEY (numero)
)
go
---------------------------
alter table habitacion
add constraint CK_tipo check ( tipo_habitacion in
('simple','doble','tiple','matrinomial','familiar','suite')),
Default ('simple') for tipo_habitacion
--------------------------------
alter table habitacion
add constraint Cke_estado check ( estado in ('reservado', 'ocupado', 'libre')),
Default ('libre') for estdo

CREATE TABLE huespedes


(
id_huesped int NOT NULL,
Nombre varchar(30),
a_paterno varchar (30),
a_materno varchar (30),
dni varchar(30),
constraint Ck_dni check(dni like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
f_entrada datetime,
f_salida datetime,
descripcion varchar(30),
CONSTRAINT PK_huespedes PRIMARY KEY (id_huesped)
)go
CREATE TABLE reservaciones
(
id_reservacion int NOT NULL,
numero int NULL,
id_huesped int NULL,
f_reservacion datetime,
f_reservada datetime,
f_salida datetime,
CONSTRAINT PK_reservaciones PRIMARY KEY (id_reservacion),
CONSTRAINT R_2 FOREIGN KEY (numero) REFERENCES habitacion(numero)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT R_3 FOREIGN KEY (id_huesped) REFERENCES huespedes(id_huesped)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
go

CREATE TABLE detalle_servicio


(
id_sa int NOT NULL,
id_reservacion int NOT NULL,
descripcion varchar(30),
CONSTRAINT PK_detalle_servicio PRIMARY KEY (id_sa ,id_reservacion),
CONSTRAINT R_11 FOREIGN KEY (id_sa) REFERENCES servicio_adicional(id_sa)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT R_12 FOREIGN KEY (id_reservacion) REFERENCES
reservaciones(id_reservacion)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
go

CREATE TABLE cliente


(
id_cliente int NOT NULL,
nombre varchar(30),
apellidos varchar(30),
dni varchar(30),
constraint CK_dni check ( dni like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
edad varchar(30),
sexo varchar(1),
constraint Ck_sexo check ( sexo in ('m','f')),
e_civil varchar(30),
constraint CK_estado check (e_civil in ('soltero','casado','divorciado')),
telefono varchar(30),
constraint CK_telefono check ( telefono like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-
9]'),
f_ingreso datetime,
f_salida datetime,
prosedencia varchar(30),
pais varchar(30),
ciudad varchar(30),
otros varchar(30),
CONSTRAINT PK_cliente PRIMARY KEY (id_cliente)
)
go

CREATE TABLE detalle_res_cliente


(
id_cliente int NOT NULL,
id_reservacion int NOT NULL,
CONSTRAINT PK_detalle_res_cliente PRIMARY KEY (id_cliente ,id_reservacion),
CONSTRAINT R_9 FOREIGN KEY (id_cliente) REFERENCES cliente(id_cliente)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT R_10 FOREIGN KEY (id_reservacion) REFERENCES
reservaciones(id_reservacion)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)
go

CREATE TABLE usuario


(
id_cliente int NOT NULL,
login varchar(30),
password varchar(30),
CONSTRAINT PK_usuario PRIMARY KEY (id_cliente)
)
go

 CREACION DE FUNCIONES

1. PRIMERA LETRA

create function primeraletra


(@tipocadena varchar (30))
returns varchar(01)
as
begin
declare @letra varchar (01)
set @letra = SUBSTRING(@tipocadena ,1, 1)
return @letra
end
select dbo.primeraletra ('Oscar')
--------------------------
2. PRIMRA PALBRA

create function dbo.PraPalabra


(@cadena varchar(30),
@palabra varchar(30),
@comt integer)
returns varchar(30)
AS
begin
declare @resul varchar(30)
if @comt<=len(@cadena)
begin
if SUBSTRING(@cadena, @comt+1, 1) in (' ')
set @resul = dbo.PraPalabra(@cadena,
@palabra+(SUBSTRING(@cadena, @comt, 1)), len(@cadena)+1)
else
set @resul = dbo.PraPalabra(@cadena,
@palabra+(SUBSTRING(@cadena, @comt, 1)), @comt+1)
end
else
set @resul = @palabra
return @resul
end
go

-------------------------------
3. CRACION DE LA ULTIMA LETRA

create function dbo.Ultima_Letra


(@cadena varchar(30))
returns varchar(01)
AS
begin
declare @letra varchar(01)
set @letra = SUBSTRING(@cadena, len(@cadena), 1)
return @letra
end
go

4. CRACION DE CONTADOR DE VOCALES


create function dbo.con_Vocales
(@cadena varchar(30),
@cuenta integer,
@coun integer)
returns integer
AS
begin
declare @contador integer
if @coun<=len(@cadena)
begin
if SUBSTRING(@cadena, @coun, 1) in ('a','e','i','o','u')
set @contador = dbo.con_Vocales(@cadena, @cuenta+1, @coun+1)
else
set @contador = dbo.con_Vocales(@cadena, @cuenta, @coun+1)
end
else
set @contador = @cuenta
return @contador
end
go

5. CREACION DE TRIGGER

create trigger TR_Generardor_Usuario


on huespedes
for insert
AS
begin
declare @id int
declare @ApPaterno varchar(30)
declare @ApMaterno varchar(30)
declare @Nombre varchar(30)
declare @Login varchar(30)
declare @Contraseña varchar(10)

select @id = id_huesped,


@ApPaterno = a_paterno,
@ApMaterno = a_materno,
@Nombre = nombre
from inserted
set @Login = dbo.primeraletra (@ApPaterno) + dbo.PraPalabra(@Nombre, '', 1) +
'@unitru.edu.pe'
set @Contraseña = LOWER(dbo.primeraletra(@ApPaterno)) +
UPPER(dbo.Ultima_Letra(@ApMaterno)) + CONVERT(varchar(02), dbo.con_Vocales(@Nombre,
0, 1)) + CONVERT(varchar(02), dbo.con_Vocales(@ApPaterno, 0, 1)) + CONVERT(varchar(02),
dbo.con_Vocales(@ApMaterno, 0, 1))

insert into USUARIO(Id_cliente, Login, password)


values(@id, @Login, @Contraseña)
end
6. DIAGRAMA DE LA BASE DE DATOS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy