Curso de MariaDB Desde la Consola/Update Replace Delete

De WikiCabal
< Curso de MariaDB Desde la Consola
Revisión del 18:51 23 oct 2015 de Rrc (discusión | contribuciones)
(dif) ← Revisión anterior | Revisión actual (dif) | Revisión siguiente → (dif)
Ir a la navegación Ir a la búsqueda

Update

  1 MariaDB [Prueba1]> CREATE TABLE Est_fruta ( id INT NOT NULL primary key auto_increment,
  2     ->                      nombre varchar (50) not null,
  3     ->                      estado varchar (15) not null );
  4 Query OK, 0 rows affected (0.22 sec)
  5 
  6 MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Manzanas', 'Maduro' );
  7 Query OK, 1 row affected (0.04 sec)
  8 
  9 MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Naranjas' , 'Podrido' );
 10 Query OK, 1 row affected (0.03 sec)
 11 
 12 MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Uvas' , 'Maduro' );
 13 Query OK, 1 row affected (0.07 sec)
 14 
 15 MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Platanos' , 'Podrido' );
 16 Query OK, 1 row affected (0.06 sec)
 17 
 18 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
 19 +----+----------+---------+
 20 | id | nombre   | estado  |
 21 +----+----------+---------+
 22 |  1 | Manzanas | Maduro  |
 23 |  2 | Naranjas | Podrido |
 24 |  3 | Uvas     | Maduro  |
 25 |  4 | Platanos | Podrido |
 26 +----+----------+---------+
 27 4 rows in set (0.00 sec)
 28 
 29 MariaDB [Prueba1]> UPDATE Est_fruta SET estado = 'Maduro';
 30 Query OK, 0 rows affected (0.03 sec)
 31 Rows matched: 4  Changed: 0  Warnings: 0
 32 
 33 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
 34 +----+----------+--------+
 35 | id | nombre   | estado |
 36 +----+----------+--------+
 37 |  1 | Manzanas | Maduro |
 38 |  2 | Naranjas | Maduro |
 39 |  3 | Uvas     | Maduro |
 40 |  4 | Platanos | Maduro |
 41 +----+----------+--------+
 42 4 rows in set (0.00 sec)
 43 
 44 MariaDB [Prueba1]> INSERT INTO Est_fruta VALUES ( NULL, 'Sandilla' , 'Maduro' );
 45 Query OK, 1 row affected (0.05 sec)
 46 
 47 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
 48 +----+----------+--------+
 49 | id | nombre   | estado |
 50 +----+----------+--------+
 51 |  1 | Manzanas | Maduro |
 52 |  2 | Naranjas | Maduro |
 53 |  3 | Uvas     | Maduro |
 54 |  4 | Platanos | Maduro |
 55 |  5 | Sandilla | Maduro |
 56 +----+----------+--------+
 57 5 rows in set (0.01 sec)
 58 
 59 MariaDB [Prueba1]> UPDATE Est_fruta SET nombre = 'Sandia' WHERE nombre = 'Sandilla'; 
 60 Query OK, 1 row affected (0.04 sec)
 61 Rows matched: 1  Changed: 1  Warnings: 0
 62 
 63 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
 64 +----+----------+--------+
 65 | id | nombre   | estado |
 66 +----+----------+--------+
 67 |  1 | Manzanas | Maduro |
 68 |  2 | Naranjas | Maduro |
 69 |  3 | Uvas     | Maduro |
 70 |  4 | Platanos | Maduro |
 71 |  5 | Sandia   | Maduro |
 72 +----+----------+--------+
 73 5 rows in set (0.00 sec)
 74 
 75 MariaDB [Prueba1]> CREATE TABLE Inv_fruta ( id int not null primary key auto_increment,
 76     ->                      nombre varchar (50) not null,
 77     ->                      color varchar (15) not null,
 78     ->                      precio float not null,
 79     ->                      cantidad int not null );
 80 Query OK, 0 rows affected (0.26 sec)
 81 
 82 MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Manzanas', 'Rojo', 5.0, 25 );
 83 Query OK, 1 row affected (0.04 sec)
 84 
 85 MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Naranjas' , 'Anaranja' , 7.5, 44 );
 86 Query OK, 1 row affected (0.04 sec)
 87 
 88 MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Uvas' , 'Verde' , 12.5, 15 );
 89 Query OK, 1 row affected (0.09 sec)
 90 
 91 MariaDB [Prueba1]> INSERT INTO Inv_fruta VALUES ( NULL, 'Platanos' , 'Amarillo' , 1.5, 36 );
 92 Query OK, 1 row affected (0.09 sec)
 93 
 94 MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
 95 +----+----------+----------+--------+----------+
 96 | id | nombre   | color    | precio | cantidad |
 97 +----+----------+----------+--------+----------+
 98 |  1 | Manzanas | Rojo     |      5 |       25 |
 99 |  2 | Naranjas | Anaranja |    7.5 |       44 |
100 |  3 | Uvas     | Verde    |   12.5 |       15 |
101 |  4 | Platanos | Amarillo |    1.5 |       36 |
102 +----+----------+----------+--------+----------+
103 4 rows in set (0.00 sec)
104 
105 MariaDB [Prueba1]> UPDATE Inv_fruta SET cantidad = cantidad - 1 WHERE id = 1;
106 Query OK, 1 row affected (0.04 sec)
107 Rows matched: 1  Changed: 1  Warnings: 0
108 
109 MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
110 +----+----------+----------+--------+----------+
111 | id | nombre   | color    | precio | cantidad |
112 +----+----------+----------+--------+----------+
113 |  1 | Manzanas | Rojo     |      5 |       24 |
114 |  2 | Naranjas | Anaranja |    7.5 |       44 |
115 |  3 | Uvas     | Verde    |   12.5 |       15 |
116 |  4 | Platanos | Amarillo |    1.5 |       36 |
117 +----+----------+----------+--------+----------+
118 4 rows in set (0.00 sec)
119 
120 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
121 +----+----------+--------+
122 | id | nombre   | estado |
123 +----+----------+--------+
124 |  1 | Manzanas | Maduro |
125 |  2 | Naranjas | Maduro |
126 |  3 | Uvas     | Maduro |
127 |  4 | Platanos | Maduro |
128 |  5 | Sandia   | Maduro |
129 +----+----------+--------+
130 5 rows in set (0.00 sec)
131 
132 MariaDB [Prueba1]> UPDATE Est_fruta SET estado = 'Podrido' WHERE id = 3;
133 Query OK, 1 row affected (0.07 sec)
134 Rows matched: 1  Changed: 1  Warnings: 0

Replace

 1 MariaDB [Prueba1]> REPLACE INTO Inv_fruta VALUES ( 3, 'Uvas', 'Purple', 12.0, 15 );
 2 Query OK, 2 rows affected (0.05 sec)
 3 
 4 REPLACE no es ANSI
 5 
 6 MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
 7 +----+----------+----------+--------+----------+
 8 | id | nombre   | color    | precio | cantidad |
 9 +----+----------+----------+--------+----------+
10 |  1 | Manzanas | Rojo     |      5 |       24 |
11 |  2 | Naranjas | Anaranja |    7.5 |       44 |
12 |  3 | Uvas     | Purple   |     12 |       15 |
13 |  4 | Platanos | Amarillo |    1.5 |       36 |
14 +----+----------+----------+--------+----------+
15 4 rows in set (0.00 sec)
16 
17 MariaDB [Prueba1]> REPLACE INTO Inv_fruta VALUES ( 5, 'Manzanas', 'Verde', 5.0, 60 );
18 Query OK, 1 row affected (0.04 sec)
19 
20 MariaDB [Prueba1]> SELECT * FROM Inv_fruta;
21 +----+----------+----------+--------+----------+
22 | id | nombre   | color    | precio | cantidad |
23 +----+----------+----------+--------+----------+
24 |  1 | Manzanas | Rojo     |      5 |       24 |
25 |  2 | Naranjas | Anaranja |    7.5 |       44 |
26 |  3 | Uvas     | Purple   |     12 |       15 |
27 |  4 | Platanos | Amarillo |    1.5 |       36 |
28 |  5 | Manzanas | Verde    |      5 |       60 |
29 +----+----------+----------+--------+----------+
30 5 rows in set (0.00 sec)

Delete

 1 MariaDB [Prueba1]> SELECT * FROM color;
 2 +----+----------+
 3 | id | nombre   |
 4 +----+----------+
 5 |  1 | Rojo     |
 6 |  2 | naranja  |
 7 |  3 | Purpura  |
 8 |  4 | Amarillo |
 9 +----+----------+
10 4 rows in set (0.00 sec)
11 
12 MariaDB [Prueba1]> DELETE FROM color;
13 Query OK, 4 rows affected (0.07 sec)
14 
15 MariaDB [Prueba1]> SELECT * FROM color;
16 Empty set (0.00 sec)
17 
18 MariaDB [Prueba1]> SELECT * FROM Est_fruta;
19 +----+----------+---------+
20 | id | nombre   | estado  |
21 +----+----------+---------+
22 |  1 | Manzanas | Maduro  |
23 |  2 | Naranjas | Maduro  |
24 |  3 | Uvas     | Podrido |
25 |  4 | Platanos | Maduro  |
26 |  5 | Sandia   | Maduro  |
27 +----+----------+---------+
28 5 rows in set (0.00 sec)
29 
30 MariaDB [Prueba1]> DELETE FROM Est_fruta WHERE estado = 'Podrido';
31 Query OK, 1 row affected (0.03 sec)
32 
33 MariaDB [Prueba1]> seMariaDB [Prueba1]> SELECT * FROM Est_fruta;
34 +----+----------+--------+
35 | id | nombre   | estado |
36 +----+----------+--------+
37 |  1 | Manzanas | Maduro |
38 |  2 | Naranjas | Maduro |
39 |  4 | Platanos | Maduro |
40 |  5 | Sandia   | Maduro |
41 +----+----------+--------+
42 4 rows in set (0.00 sec)