Вы находитесь на странице: 1из 22

mysql> create database nomina;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;


+--------------------+
| Database

+--------------------+
| information_schema |
| mysql

| nomina

| phpmyadmin
| test

+--------------------+
5 rows in set (0.05 sec)

mysql> use nomina;


Database changed
mysql> create table Empleado(
-> idEmpleado int not null,
-> nombre varchar(20),
-> sueldo double not null,
-> primary key (idEmpleado));
Query OK, 0 rows affected (0.05 sec)

mysql> show tables;


+------------------+
| Tables_in_nomina |
+------------------+
| empleado

+------------------+
1 row in set (0.00 sec)

mysql> describe Empleado;


+------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre
| sueldo

| NO | PRI |

| varchar(20) | YES |
| double

| NO |

| NULL |
|

+------------+-------------+------+-----+---------+-------+
3 rows in set (0.03 sec)

mysql> create table Personas(


-> id int auto_increment primary key,
-> nombre varchar(40),
-> fecha date);
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;


+------------------+
| Tables_in_nomina |
+------------------+
| empleado
| personas

|
|

+------------------+
2 rows in set (0.00 sec)

mysql> desc Personas;


+--------+-------------+------+-----+---------+----------------+
| Field | Type

| Null | Key | Default | Extra

+--------+-------------+------+-----+---------+----------------+
| id

| int(11)

| NO | PRI | NULL | auto_increment |

| nombre | varchar(40) | YES |


| fecha | date

| YES |

| NULL |

| NULL |

|
|

+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> create table impositor(


-> nombre_cliente varchar(20),
-> numero_cuenta char(10),
-> primary key(nombre_cliente,numero_cuenta));

Query OK, 0 rows affected (0.03 sec)

mysql> desc impositor;


+----------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+----------------+-------------+------+-----+---------+-------+
| nombre_cliente | varchar(20) | NO | PRI |

| numero_cuenta | char(10) | NO | PRI |

+----------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> alter table empleado add FechaIngreso date;


Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc empleado;


+--------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre
| sueldo

| NO | PRI |

| varchar(20) | YES |
| double

| FechaIngreso | date

| NO |
| YES |

| NULL |
|

| NULL |

+--------------+-------------+------+-----+---------+-------+

4 rows in set (0.00 sec)

mysql> alter table empleado add Sexo char(1);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table empleado change Sexo Sex char(1);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc empleado;


+--------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre
| sueldo

| varchar(20) | YES |
| double

| NO |

| FechaIngreso | date
| Sex

| NO | PRI |

| char(1)

| YES |

| NULL |

| YES |

| NULL |

| NULL

|
|

+--------------+-------------+------+-----+---------+-------+
5 rows in set (0.02 sec)

mysql> alter table empleado drop sueldo;


Query OK, 0 rows affected (0.05 sec)

Records: 0 Duplicates: 0 Warnings: 0

mysql> desc empleado;


+--------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre

| varchar(20) | YES |

| FechaIngreso | date
| Sex

| NO | PRI |

| char(1)

| YES |
| YES |

| NULL |

| NULL |

| NULL |

+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table empleado drop primary key;


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc empleado;


+--------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre

| NO |

| varchar(20) | YES |

| FechaIngreso | date

| YES |

| NULL |
| NULL |

|
|
|

| Sex

| char(1)

| YES |

| NULL |

+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table empleado add primary key (idEmpleado);


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc empleado;


+--------------+-------------+------+-----+---------+-------+
| Field

| Type

| Null | Key | Default | Extra |

+--------------+-------------+------+-----+---------+-------+
| idEmpleado | int(11)
| nombre

| varchar(20) | YES |

| FechaIngreso | date
| Sex

| NO | PRI |

| char(1)

| YES |
| YES |

| NULL |
| NULL |

| NULL |

+--------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> alter table empleado rename Empleado2


-> ;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;

|
|

+------------------+
| Tables_in_nomina |
+------------------+
| empleado2

| impositor

| personas

+------------------+
3 rows in set (0.00 sec)

mysql> desc personas;


+--------+-------------+------+-----+---------+----------------+
| Field | Type

| Null | Key | Default | Extra

+--------+-------------+------+-----+---------+----------------+
| id

| int(11)

| NO | PRI | NULL | auto_increment |

| nombre | varchar(40) | YES |


| fecha | date

| YES |

| NULL |

| NULL |

|
|

+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> insert into personas values('','juan','2013-03-04');


Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> desc personas;


+--------+-------------+------+-----+---------+----------------+

| Field | Type

| Null | Key | Default | Extra

+--------+-------------+------+-----+---------+----------------+
| id

| int(11)

| NO | PRI | NULL | auto_increment |

| nombre | varchar(40) | YES |


| fecha | date

| YES |

| NULL |

| NULL |

|
|

+--------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 1 | juan | 2013-03-04 |
+----+--------+------------+
1 row in set (0.00 sec)

mysql> insert into personas values('','peter','2013-03-04');


Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha
+----+--------+------------+

| 1 | juan | 2013-03-04 |
| 2 | peter | 2013-03-04 |
+----+--------+------------+
2 rows in set (0.02 sec)

mysql> insert into personas values('','maria','2013-04-04');


Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 1 | juan | 2013-03-04 |
| 2 | peter | 2013-03-04 |
| 3 | Maria | 0000-00-00 |
| 4 | Maria | 0000-00-00 |
| 5 | Maria | 0000-00-00 |
| 6 | maria | 2013-04-04 |
+----+--------+------------+
6 rows in set (0.00 sec)

mysql> delete from personas where id='3';


Query OK, 1 row affected (0.02 sec)

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 1 | juan | 2013-03-04 |
| 2 | peter | 2013-03-04 |
| 4 | Maria | 0000-00-00 |
| 5 | Maria | 0000-00-00 |
| 6 | maria | 2013-04-04 |
+----+--------+------------+
5 rows in set (0.00 sec)

mysql> delete from personas where id='4';


Query OK, 1 row affected (0.00 sec)

mysql> delete from personas where id='5';


Query OK, 1 row affected (0.00 sec)

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 1 | juan | 2013-03-04 |
| 2 | peter | 2013-03-04 |

| 6 | maria | 2013-04-04 |
+----+--------+------------+
3 rows in set (0.00 sec)

mysql> delete from personas;


Query OK, 3 rows affected (0.00 sec)

mysql> select * from personas;


Empty set (0.00 sec)

mysql> insert into personas values(


-> '','Pedro','2014-04-07');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select *from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 7 | Pedro | 2014-04-07 |
+----+--------+------------+
1 row in set (0.00 sec)

mysql> insert into personas values(


-> '','Juan','2014-01-10');

Query OK, 1 row affected, 1 warning (0.02 sec)

mysql> select *from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 7 | Pedro | 2014-04-07 |
| 8 | Juan | 2014-01-10 |
+----+--------+------------+
2 rows in set (0.00 sec)

mysql> update personas set fecha='20104-11-11' where id='7';


Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> select * from personas;
+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 7 | Pedro | 0000-00-00 |
| 8 | Juan | 2014-01-10 |
+----+--------+------------+
2 rows in set (0.00 sec)

mysql> update personas set fecha='2014-11-11' where id='7';

Query OK, 1 row affected (0.00 sec)


Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from personas;


+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 7 | Pedro | 2014-11-11 |
| 8 | Juan | 2014-01-10 |
+----+--------+------------+
2 rows in set (0.00 sec)
mysql> update personas set nombre='Nieves' where id='8';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from personas;
+----+--------+------------+
| id | nombre | fecha

+----+--------+------------+
| 7 | Pedro | 2014-11-11 |
| 8 | Nieves | 2014-01-10 |
+----+--------+------------+
2 rows in set (0.00 sec)

mysql> create database peritaje;


Query OK, 1 row affected (0.03 sec)
mysql> use peritaje;
Database changed
mysql> create table persona(
dni int auto_increment primary key,
nombre varchar(30) not null,
dir varchar(50) not null,
tel varchar(15) not null);
Query OK, 0 rows affected (0.06 sec)
mysql> describe persona;
+--------+-------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
+--------+-------------+------+-----+---------+----------------+
| dni | int(11) | NO | PRI | NULL | auto_increment |
| nombre | varchar(30) | NO | |
| dir | varchar(50) | NO | |
| tel | varchar(15) | NO | |
+--------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
mysql> create table vehiculo(

matricula varchar(10) primary key,


marca varchar (10) not null,
modelo int not null,
color varchar(10) not null,
dni int,
foreign key (dni) references persona(dni));
Query OK, 0 rows affected (0.11 sec)
mysql> describe vehiculo;

+-----------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| matricula | varchar(10) | NO | PRI |
| marca | varchar(10) | NO | |
| modelo | int(11) | NO | |
| color | varchar(10) | NO | |
| dni | int(11) | YES | MUL | NULL |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> create table accidente(
codigoacc int auto_increment primary key,
hora time not null,
fecha date not null,
lugar varchar (35) not null,
matricula varchar (10),

dni int,
foreign key (matricula) references vehiculo(matricula),
foreign key (dni) references persona (dni));
Query OK, 0 rows affected (0.15 sec)
mysql> describe accidente;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
+-----------+-------------+------+-----+---------+----------------+
| codigoacc | int(11) | NO | PRI | NULL | auto_increment |
| hora| time| NO | |
| fecha | date| NO | |
| lugar | varchar(35) | NO | |
| matricula | varchar(10) | YES | MUL | NULL |
| dni
| int(11) | YES | MUL | NULL |
+-----------+-------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> create table multa(


codigomul int auto_increment primary key,
fecha date not null,
hora time not null,
lugar varchar (35) not null,
importe double not null,
matricula varchar (10),

dni int,
foreign key (matricula) references vehiculo(matricula),
foreign key (dni) references persona(dni));
Query OK, 0 rows affected (0.08 sec)
mysql> describe multa;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
+-----------+-------------+------+-----+---------+----------------+
| codigomul | int(11) | NO | PRI | NULL | auto_increment |
| fecha | date | NO |
| hora | time | NO | |
| lugar | varchar(35) | NO | |
| matricula | varchar(10) | YES | MUL | NULL |
| dni | int(11) | YES | MUL | NULL |
+-----------+-------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> insert into persona values(


-> ' ', "Pedro", "La Gloria","229494942");
Query OK, 1 row affected, 1 warning (0.10 sec)

mysql> insert into persona values(


-> ' ', "Maria", "Independencia","123456");
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into persona values(


-> ' ', "Juan", "Juarez","098765");
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from persona;


+-----+--------+---------------+-------+
| dni | nombre | dir | tel |
+-----+--------+---------------+-------+
| 1 | Pedro | La Gloria | 229494942 |
| 2 | Maria | Independencia | 123456 |
| 3 | Juan| Juarez| 098765|
+-----+--------+---------------+-------+
3 rows in set (0.00 sec)
mysql> insert into vehiculo values(
-> "ABC123","Stratus",97,"Azul",1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into vehiculo values(
-> "DEF456","Pointer",2011,"Rojo",2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into vehiculo values(
-> "HIJ789","Chevy",2010,"Blanco",3);

Query OK, 1 row affected (0.00 sec)


mysql> select * from vehiculo;
+-----------+-------+--------+--------+------+
| matricula | marca | modelo | color | dni |
+-----------+-------+--------+--------+------+
| ABC123 | Stratus |97 | Azul | 1 |
| DEF456 | Pointer | 2011 | Rojo | 2 |
| HIJ789 | Chevy | 2010 | Blanco | 3 |
+-----------+-------+--------+--------+------+
3 rows in set (0.00 sec)
mysql> insert into accidente values(
-> ' ', "09:25:01","2010-06-06","SAT","ABC123",1);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> insert into accidente values(
-> ' ', "10:30:06","2010-07-07","SANTIAGO","DEF456",2);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> insert into accidente values(
-> ' ', "23:15:09","2010-08-09","CATEMACO","HIJ789",3);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from accidente;
+-----------+----------+------------+----------+-----------+------+
| codigoacc | hora
| fecha
| lugar | matricula | dni |
+-----------+----------+------------+----------+-----------+------+
1 | 09:25:01 | 2010-06-06 | SAT

| ABC123 | 1 |

2 | 10:30:06 | 2010-07-07 | SANTIAGO | DEF456 | 2 |


3 | 23:15:09 | 2010-08-09 | CATEMACO | HIJ789 | 3 |
+-----------+----------+------------+----------+-----------+------+
3 rows in set (0.00 sec)
mysql> insert into multa values(
-> ' ', "2010-06-07","09:30:00", "SAT",1597.85,"ABC123",1);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> insert into multa values(
-> ' ', "2010-07-08","09:30:00", "SAT",259.60,"DEF456",2);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> insert into multa values(
-> ' ', "2010-08-10","09:30:00", "SAT",5348.16,"HIJ789",3);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from multa;


+-----------+------------+----------+-------+---------+-----------+------+
| codigomul | fecha
| hora
| lugar | importe | matricula | dni |
+-----------+------------+----------+-------+---------+-----------+------+
1 | 2010-06-07 | 09:30:00 | SAT | 1597.85 | ABC123 | 1 |
2 | 2010-07-08 | 09:30:00 | SAT | 259.6 | DEF456 | 2 |
3 | 2010-08-10 | 09:30:00 | SAT | 5348.16 | HIJ789 | 3 |
+-----------+------------+----------+-------+---------+-----------+------+
3 rows in set (0.00 sec)

Вам также может понравиться