Sercoguido

Actividad 1.2

Aug 26th, 2024 (edited)
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.72 KB | None | 0 0
  1. create database Libreria
  2. go
  3. use Libreria
  4. go
  5.  
  6. create table Provincias(
  7. ID_Provincia int not null identity(1,1) primary key,
  8. Nombre varchar(30) not null unique
  9. )
  10. go
  11. create table Paises(
  12. ID_Pais int not null identity(1,1) primary key,
  13. Nombre varchar(30) not null unique
  14. )
  15. go
  16. create table Direcciones(
  17. ID_Direccion int not null identity(1,1) primary key,
  18. ID_Pais int not null foreign key references Paises(ID_Pais),
  19. ID_Provincia int not null foreign key references Provincias(ID_Provincia),
  20. Calle varchar(30) not null,
  21. Altura smallint not null
  22. )
  23. go
  24. create table Clientes(
  25. ID_Cliente int not null identity(1,1) primary key,
  26. Nombre varchar(30) not null,
  27. Apellido varchar(30) not null,
  28. Correo_Electronico varchar(30) not null,
  29. Fecha_Nacimiento date not null,
  30. ID_Direccion int not null foreign key references Direcciones(ID_Direccion)
  31. )
  32. go
  33. create table Categorias(
  34. ID_Categoria int not null identity(1,1) primary key,
  35. Nombre_Categoria varchar(30) not null,
  36. )
  37. go
  38. create table Autores(
  39. ID_Autor int not null identity(1,1) primary key,
  40. ID_Pais int null foreign key references Paises(ID_Pais),
  41. Nombre_Autor varchar(30) not null
  42. )
  43. go
  44. create table Libros(
  45. ID_Libro int not null identity(1,1) primary key,
  46. Titulo varchar(30) not null,
  47. Año_Publicacion smallint not null,
  48. ID_Categoria int not null foreign key references Categorias (ID_Categoria),
  49. ID_Autor int null foreign key references Autores (ID_Autor),
  50. )
  51. go
  52. create table Libros_X_Clientes(
  53. ID_Compra int not null identity(1,1) primary key,
  54. ID_Cliente int not null foreign key references Clientes(ID_Cliente),
  55. ID_Libro int not null foreign key references Libros(ID_Libro),
  56. Fecha_Compra date not null,
  57. Puntaje tinyint null check (puntaje>=0 AND puntaje <=10)
  58. )
  59.  
Advertisement
Add Comment
Please, Sign In to add comment