Biblioteca
PRIMARY KEY: identifica de manera única a cada fila de la tabla mediante una o varias columas, estas columnas que forman la clave primaria no pueden tener valores nulos.
FOREIGN KEY: establece una relación entre una(s) columna(s) de la tabla y otra(s) columna(s) de la tabla referenciada, siendo esta última(s) columna(s) laPRIMARY KEY
UNIQUE: no permite duplicados; combinado con NOT NULL es la forma de definir una clave alternativa.
CHECK: especifica una condición que se debe evaluar a "cierto".
create table editorial
(claveeditorial smallint,
nombre varchar (60),
direccion varchar (60),
telefono varchar (15),
primary key (claveeditorial))engine=innodb;
Query OK, 0 rows affected (0.15 sec)create table socio
(clavesocio int,
nombre varchar (60),
direccion varchar (60),
telefono varchar (15),
categoria char,
primary key (clavesocio))engine=innodb;
Query OK, 0 rows affected (0.03 sec)
create table tema
(clavetema smallint,
nombre varchar(40),
primary key (clavetema))engine=innodb;
Query OK, 0 rows affected (0.01 sec)
create table autor(claveautor int,
nombre varchar(60),
primary key (claveautor))engine=innodb;
Query OK, 0 rows affected (0.01 sec)
mysql> use biblioteca
Database changed
mysql> show tables
-> ;
Empty set (0.00 sec)
mysql> create table editorial
-> (claveeditorial smallint,
-> nombre varchar (60),
-> direccion varchar (60),
-> telefono varchar (60),
-> primary keyclaveeditorial)
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ')' at
line 6
mysql> create table editorial
-> (claveeditorial smallint,
-> nombre varchar (60),
-> direccion varchar (60),
-> telefono varchar (60),
-> primary key claveeditorial
-> Ctrl-C -- exit!
ByeC:\xampp\mysql\bin>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of theirrespective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use biblioteca
Database changed
mysql> show tables
-> ;
Empty set (0.00 sec)
mysql> create table editorial
-> (claveeditorial smallint,
-> nombre varchar (60),
-> direccion varchar (60),
-> telefono varchar (15),
-> primary key (claveeditorial))engine=innodb;
Query OK, 0 rowsaffected (0.15 sec)
mysql> create table socio
-> (clavesocio int,
-> nombre varchar (60),
-> direccion varchar (60),
-> telefono varchar (15),
-> categoria char,
-> primary key (clavesocio))engine=innodb;
Query OK, 0 rows affected (0.03 sec)
mysql> create table tema
-> (clavetema smallint,
-> nombre varchar(40),
-> primary key (clavetema))engine=innodb;
QueryOK, 0 rows affected (0.01 sec)
create table autor
(claveautor int,
nombre varchar(60),
primary key (claveautor))engine=innodb;
Query OK, 0 rows affected (0.01 sec)
create table libro
(clavelibro int,
titulo varchar(60),
idioma varchar(15),
formato varchar (15),
claveeditorial smallint,
primary key (clavelibro),
foreign key (claveeditorial) references editorial(claveeditorial))engine=innodb;
create table tratasobre
(clavelibro int,
clavetema smallint,
primary key (clavelibro,clavetema),
foreign key (clavelibro) references libro (clavelibro),
foreign key (clavetema) references tema (clavetema))engine=innodb;
create table escritopor
(claveautor int,
clavelibro int,
primary key (claveautor,clavelibro),
foreign key (clavelibro) references libro (clavelibro),
foreign...
Regístrate para leer el documento completo.