BD BIBLIOTECA
COMO MONTAR EL MODELO ANTERIOR EN MYSQL
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| phpmyadmin |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database biblioteca;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| biblioteca |
| mysql |
| phpmyadmin |
| test |
+--------------------+
5 rows in set (0.00 sec)
para abrir la base de datos y poder usarla...
mysql> use biblioteca;
Para crear la tabla libro
mysql> create table libro
-> (cod_lib char(10) not null primary key,
-> nombre char(40) not null)engine=innodb;
Query OK, 0 rows affected (0.19 sec)
Para crear la tabla autor
mysql> create table autor
-> (cod_aut char(10) not null primary key,
-> nom_lib char(40) not null)engine=innodb;
Query OK, 0 rows affected (0.14 sec)
Para crear la tabla lib_aut
mysql> create table lib_aut
-> (cod_lib char(10) not null,
-> cod_aut char(10) not null,
-> foreign key(cod_lib) references libro(cod_lib) on delete cascade on updat
e cascade,
-> foreign key(cod_aut) references autor(cod_aut) on delete cascade on updat
e cascade)engine=innodb;
Query OK, 0 rows affected (0.17 sec)
Para ver las tablas creadas
mysql> show tables;
+----------------------+
| Tables_in_biblioteca |
+----------------------+
| autor |
| lib_aut |
| libro |
+----------------------+
3 rows in set (0.00 sec)
Ver la estructura de la tabla
mysql> describe autor;
+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_aut | char(10) | NO | PRI | NULL | |
| nom_lib | char(40) | NO | | NULL | |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> show create table autor;
+-------+-----------------------------------------------------------------------
-------------------------------------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
-------------------------------------------------------------------------------+
| autor | CREATE TABLE `autor` (
`cod_aut` char(10) NOT NULL,
`nom_lib` char(40) NOT NULL,
PRIMARY KEY (`cod_aut`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------
-------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
mysql> describe libro;
+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| cod_lib | char(10) | NO | PRI | NULL | |
| nombre | char(40) | NO | | NULL | |
+---------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> insert into libro(cod_lib,nombre) values('00001','Java');
Query OK, 1 row affected (0.05 sec)
como insertarle registros a la tabla
mysql> insert into libro values('00002','BD'),('00003','auditoria');
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
para ver la información de la tabla
mysql> select * from libro;
+---------+-----------+
| cod_lib | nombre |
+---------+-----------+
| 00001 | Java |
| 00002 | BD |
| 00003 | auditoria |
+---------+-----------+
3 rows in set (0.00 sec)
Leer más: https://sistemasremington.webnode.com/base-de-datos/comandos-mysql-para-bd/
Crea tu propia web gratis: https://www.webnode.es