Curso de MariaDB Desde la Consola/Update Replace Delete

De WikiCabal
Saltar a: navegación, buscar

Update

MariaDB [Prueba1]> CREATE TABLE Est_fruta ( id INT NOT NULL primary key auto_increment,
    ->                      nombre varchar (50) not null,
    ->                      estado varchar (15) not null );
Query OK, 0 rows affected (0.22 sec)

MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Manzanas', 'Maduro' );
Query OK, 1 row affected (0.04 sec)

MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Naranjas' , 'Podrido' );
Query OK, 1 row affected (0.03 sec)

MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Uvas' , 'Maduro' );
Query OK, 1 row affected (0.07 sec)

MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Platanos' , 'Podrido' );
Query OK, 1 row affected (0.06 sec)

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+---------+
| id | nombre   | estado  |
+----+----------+---------+
|  1 | Manzanas | Maduro  |
|  2 | Naranjas | Podrido |
|  3 | Uvas     | Maduro  |
|  4 | Platanos | Podrido |
+----+----------+---------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> UPDATE Est_fruta SET estado = 'Maduro';
Query OK, 0 rows affected (0.03 sec)
Rows matched: 4  Changed: 0  Warnings: 0

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+--------+
| id | nombre   | estado |
+----+----------+--------+
|  1 | Manzanas | Maduro |
|  2 | Naranjas | Maduro |
|  3 | Uvas     | Maduro |
|  4 | Platanos | Maduro |
+----+----------+--------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Sandilla' , 'Maduro' );
Query OK, 1 row affected (0.05 sec)

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+--------+
| id | nombre   | estado |
+----+----------+--------+
|  1 | Manzanas | Maduro |
|  2 | Naranjas | Maduro |
|  3 | Uvas     | Maduro |
|  4 | Platanos | Maduro |
|  5 | Sandilla | Maduro |
+----+----------+--------+
5 rows in set (0.01 sec)

MariaDB [Prueba1]> UPDATE Est_fruta SET nombre = 'Sandia' WHERE nombre = 'Sandilla'; 
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+--------+
| id | nombre   | estado |
+----+----------+--------+
|  1 | Manzanas | Maduro |
|  2 | Naranjas | Maduro |
|  3 | Uvas     | Maduro |
|  4 | Platanos | Maduro |
|  5 | Sandia   | Maduro |
+----+----------+--------+
5 rows in set (0.00 sec)

MariaDB [Prueba1]> CREATE TABLE Inv_fruta ( id int not null primary key auto_increment,
    ->                      nombre varchar (50) not null,
    ->                      color varchar (15) not null,
    ->                      precio float not null,
    ->                      cantidad int not null );
Query OK, 0 rows affected (0.26 sec)

MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Manzanas', 'Rojo', 5.0, 25 );
Query OK, 1 row affected (0.04 sec)

MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Naranjas' , 'Anaranja' , 7.5, 44 );
Query OK, 1 row affected (0.04 sec)

MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Uvas' , 'Verde' , 12.5, 15 );
Query OK, 1 row affected (0.09 sec)

MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Platanos' , 'Amarillo' , 1.5, 36 );
Query OK, 1 row affected (0.09 sec)

MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
+----+----------+----------+--------+----------+
| id | nombre   | color    | precio | cantidad |
+----+----------+----------+--------+----------+
|  1 | Manzanas | Rojo     |      5 |       25 |
|  2 | Naranjas | Anaranja |    7.5 |       44 |
|  3 | Uvas     | Verde    |   12.5 |       15 |
|  4 | Platanos | Amarillo |    1.5 |       36 |
+----+----------+----------+--------+----------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> UPDATE Inv_fruta SET cantidad = cantidad - 1 WHERE id = 1;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
+----+----------+----------+--------+----------+
| id | nombre   | color    | precio | cantidad |
+----+----------+----------+--------+----------+
|  1 | Manzanas | Rojo     |      5 |       24 |
|  2 | Naranjas | Anaranja |    7.5 |       44 |
|  3 | Uvas     | Verde    |   12.5 |       15 |
|  4 | Platanos | Amarillo |    1.5 |       36 |
+----+----------+----------+--------+----------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+--------+
| id | nombre   | estado |
+----+----------+--------+
|  1 | Manzanas | Maduro |
|  2 | Naranjas | Maduro |
|  3 | Uvas     | Maduro |
|  4 | Platanos | Maduro |
|  5 | Sandia   | Maduro |
+----+----------+--------+
5 rows in set (0.00 sec)

MariaDB [Prueba1]> UPDATE Est_fruta SET estado = 'Podrido' WHERE id = 3;
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Replace

MariaDB [Prueba1]> REPLACE INTO Inv_fruta VALUES ( 3, 'Uvas', 'Purple', 12.0, 15 );
Query OK, 2 rows affected (0.05 sec)

REPLACE no es ANSI

MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
+----+----------+----------+--------+----------+
| id | nombre   | color    | precio | cantidad |
+----+----------+----------+--------+----------+
|  1 | Manzanas | Rojo     |      5 |       24 |
|  2 | Naranjas | Anaranja |    7.5 |       44 |
|  3 | Uvas     | Purple   |     12 |       15 |
|  4 | Platanos | Amarillo |    1.5 |       36 |
+----+----------+----------+--------+----------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> REPLACE INTO Inv_fruta VALUES ( 5, 'Manzanas', 'Verde', 5.0, 60 );
Query OK, 1 row affected (0.04 sec)

MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
+----+----------+----------+--------+----------+
| id | nombre   | color    | precio | cantidad |
+----+----------+----------+--------+----------+
|  1 | Manzanas | Rojo     |      5 |       24 |
|  2 | Naranjas | Anaranja |    7.5 |       44 |
|  3 | Uvas     | Purple   |     12 |       15 |
|  4 | Platanos | Amarillo |    1.5 |       36 |
|  5 | Manzanas | Verde    |      5 |       60 |
+----+----------+----------+--------+----------+
5 rows in set (0.00 sec)

Delete

MariaDB [Prueba1]> SELECT * FROM color;
+----+----------+
| id | nombre   |
+----+----------+
|  1 | Rojo     |
|  2 | naranja  |
|  3 | Purpura  |
|  4 | Amarillo |
+----+----------+
4 rows in set (0.00 sec)

MariaDB [Prueba1]> DELETE FROM color;
Query OK, 4 rows affected (0.07 sec)

MariaDB [Prueba1]> SELECT * FROM color;
Empty set (0.00 sec)

MariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+---------+
| id | nombre   | estado  |
+----+----------+---------+
|  1 | Manzanas | Maduro  |
|  2 | Naranjas | Maduro  |
|  3 | Uvas     | Podrido |
|  4 | Platanos | Maduro  |
|  5 | Sandia   | Maduro  |
+----+----------+---------+
5 rows in set (0.00 sec)

MariaDB [Prueba1]> DELETE FROM Est_fruta WHERE estado = 'Podrido';
Query OK, 1 row affected (0.03 sec)

MariaDB [Prueba1]> seMariaDB [Prueba1]> SELECT * FROM Est_fruta;
+----+----------+--------+
| id | nombre   | estado |
+----+----------+--------+
|  1 | Manzanas | Maduro |
|  2 | Naranjas | Maduro |
|  4 | Platanos | Maduro |
|  5 | Sandia   | Maduro |
+----+----------+--------+
4 rows in set (0.00 sec)