100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Practica de Sql Server $13.09   Add to cart

Class notes

Practica de Sql Server

 7 views  0 purchase
  • Course
  • Institution

Practica para Sql (Practica para Sql)

Preview 2 out of 8  pages

  • March 18, 2021
  • 8
  • 2019/2020
  • Class notes
  • Francisco
  • All classes
avatar-seller
Una biblioteca quiere diseñar una BD de la información que maneja. Para ello decide crear una
base de datos BDBIBLIOTECA. En esta base de datos se decide crear una tabla LIBROS con la
información relativa a cada uno de los libros de que se dispone y otra tabla PRÉSTAMOS donde quedará
registrada la información relativa a cada uno de los préstamos que se realice.

La descripción de las tablas es la siguiente:



LIBROS
CODIGO Alfanumérico de 8 posiciones
TITULO Alfanumérico de 30 posiciones
AUTOR Alfanumérico de 30 posiciones
TOTAL_EJEMPLARES Numérico de 2 posiciones
TOTAL_PRESTAMO Numérico de 2 posiciones

TOTAL_EJEMPLARES indica el número de ejemplares de que se dispone de ese libro y
TOTAL_PRESTAMO indica el número de ejemplares que está en préstamo es ese momento.


PRESTAMOS
NUMERO Numérico de 2 posiciones
ID_LIBRO Alfanumérico de 8 posiciones
NIF Alfanumérico de 10
FECHA_PRESTAMO DATETIME
FECHA_DEVOLUCION DATETIME

FECHA_DEVOLUCION indica la fecha en la que se ha devuelto el libro. Los libros que tienen el valor
NULL en la columna Fecha_devoluación son aquellos que en este momento están en préstamo


Se pide realizar las sentencias Sql que correspondan a los siguientes Enunciados:

1 – Comprobar la versión de SQL con la que está trabajando.

SELECT @@VERSION




3

, 2 – a) Crear una base de datos BDBIBLIOTECA

CREATE DATABASE BD_BIBLIOTECAS

use BD_BIBLIOTECAS

3 – a) Crear las tablas con las siguientes restricciones:

LIBROS
 CODIGO Clave primaria
 TITULO No nulo
 AUTOR No nulo
 TITULO y AUTOR Único


--CREANDO LA TABLA LIBROS

CREATE TABLE LIBROS
(
CODIGO NVARCHAR(8) CONSTRAINT PK_LIBROS PRIMARY KEY(CODIGO),
TITULO NVARCHAR(30)NOT NULL CONSTRAINT UQ_TITULO UNIQUE,
AUTOR NVARCHAR(30) NOT NULL CONSTRAINT UQ_AUTOR,
TOTAL_EJEMPLARES NUMERIC(2),
TOTAL_PRESTAMO NUMERIC(2)
)

PRESTAMOS

 NUMERO Clave primaria
 ID_LIBRO Clave ajena referenciando a CODIGO de la tabla LIBROS con el
nombre FK_LIBROS. No nulo
 NIF No nulo
 FECHA_PRETAMO No nulo


CREATE TABLE PRESTAMOS
(
NUMERO NUMERIC(2), CONSTRAINT PK_PRESTAMOS PRIMARY KEY(NUMERO),
ID_LIBRO NVARCHAR(8)CONSTRAINT FK_LIBROS FOREIGN KEY REFERENCES
LIBROS(CODIGO)NOT NULL,
NIF NVARCHAR (10)NOT NULL,
FECHA_PRESTAMO DATETIME NOT NULL,
FECHA_DEVOLUCION DATETIME
)

4 – a) Insertar las filas para que el contenido de las tablas sea:

TABLA LIBROS

Codigo Título Autor Total ejemplares Total préstamo

ABS/1234 LA COLMENA CAMILO JOSE CELA 5 2
BBC/3456 NIEBLA MIGUEL DE UNAMUNO 7 1
BCD/1111 EL QUIJOTE MIGUEL DE CERVANTES 10 1
BDF/2255 LA VIDA ES SUEÑO CALDERON DE LA BARCA 5 0

Total_ejemplares indica el número de ejemplares del mismo libro que hay en la biblioteca y
Total_prestamo el número de ejemplares que en este momento están prestados




3

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller rubenbalbi. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $13.09. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

73243 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$13.09
  • (0)
  Add to cart