You are on page 1of 2

CREATE TABLE alumno

(
id_alumno char(10) NOT NULL ,
nombre char(20) NULL ,
apellido char(20) NULL ,
dni char(18) NULL ,
nomlibro char(20) NULL
)
go

CREATE TABLE libros


(
id_libros char(20) NOT NULL ,
nomlibro char(20) NULL ,
autor char(20) NULL ,
editorial char(20) NULL ,
especilalidad char(20) NULL ,
id_editorial char(20) NOT NULL
)
go

CREATE TABLE especialidad


(
id_especialidad char(20) NOT NULL ,
autor char(20) NULL ,
editorial char(20) NULL ,
id_libros char(20) NOT NULL ,
id_editorial char(20) NOT NULL
)
go

CREATE TABLE autores


(
id_autor char(20) NOT NULL ,
nombre char(20) NULL ,
libros char(20) NULL ,
id_libros char(20) NOT NULL ,
id_editorial char(20) NOT NULL
)
go

CREATE TABLE editorial


(
id_editorial char(20) NOT NULL ,
nomeditorial char(20) NULL ,
nombre_autor char(20) NULL ,
especialidad char(20) NULL ,
nomlibro char(18) NULL
)
go
ALTER TABLE alumno
ADD CONSTRAINT XPKalumno PRIMARY KEY CLUSTERED (id_alumno ASC)
go

ALTER TABLE libros


ADD CONSTRAINT XPKlibros PRIMARY KEY CLUSTERED (id_libros ASC,id_editorial ASC)
go

ALTER TABLE especialidad


ADD CONSTRAINT XPKespecialidad PRIMARY KEY CLUSTERED (id_especialidad
ASC,id_libros ASC,id_editorial ASC)
go

ALTER TABLE autores


ADD CONSTRAINT XPKautores PRIMARY KEY CLUSTERED (id_autor ASC,id_libros
ASC,id_editorial ASC)
go

ALTER TABLE editorial


ADD CONSTRAINT XPKeditorial PRIMARY KEY CLUSTERED (id_editorial ASC)
go

ALTER TABLE libros


ADD CONSTRAINT R_8 FOREIGN KEY (id_editorial) REFERENCES
editorial(id_editorial)
ON DELETE NO ACTION
ON UPDATE NO ACTION
go

ALTER TABLE especialidad


ADD CONSTRAINT R_3 FOREIGN KEY (id_libros,id_editorial) REFERENCES
libros(id_libros,id_editorial)
ON DELETE NO ACTION
ON UPDATE NO ACTION
go

ALTER TABLE autores


ADD CONSTRAINT R_4 FOREIGN KEY (id_libros,id_editorial) REFERENCES
libros(id_libros,id_editorial)
ON DELETE NO ACTION
ON UPDATE NO ACTION
go

You might also like