Curso de MariaDB Desde la Consola/Update Replace
Ir a la navegación
Ir a la búsqueda
Update Replace
1 MariaDB [Prueba1]> show databases;
2 +--------------------+I
3 | Database |
4 +--------------------+
5 | Prueba1 |
6 | information_schema |
7 | mysql |
8 | performance_schema |
9 +--------------------+
10 4 rows in set (0.01 sec)
11
12 MariaDB [Prueba1]> show tables;
13 +-------------------+
14 | Tables_in_Prueba1 |
15 +-------------------+
16 | Competiciones |
17 | inven |
18 | personas |
19 +-------------------+
20 3 rows in set (0.00 sec)
21
22 MariaDB [Prueba1]> create table Est_fruta ( id int not null primary key auto_increment,
23 -> nombre varchar (50) not null,
24 -> estado varchar (15) not null );
25 Query OK, 0 rows affected (0.22 sec)
26
27 MariaDB [Prueba1]> insert into Est_fruta values ( NULL, 'Manzanas', 'Maduro' );
28 Query OK, 1 row affected (0.04 sec)
29
30 MariaDB [Prueba1]> insert into Est_fruta values ( NULL, 'Naranjas' , 'Podrido' );
31 Query OK, 1 row affected (0.03 sec)
32
33 MariaDB [Prueba1]> insert into Est_fruta values ( NULL, 'Uvas' , 'Maduro' );
34 Query OK, 1 row affected (0.07 sec)
35
36 MariaDB [Prueba1]> insert into Est_fruta values ( NULL, 'Platanos' , 'Podrido' );
37 Query OK, 1 row affected (0.06 sec)
38
39 MariaDB [Prueba1]> select * from Est_fruta;
40 +----+----------+---------+
41 | id | nombre | estado |
42 +----+----------+---------+
43 | 1 | Manzanas | Maduro |
44 | 2 | Naranjas | Podrido |
45 | 3 | Uvas | Maduro |
46 | 4 | Platanos | Podrido |
47 +----+----------+---------+
48 4 rows in set (0.00 sec)
49
50 MariaDB [Prueba1]> update Est_fruta set estado = 'Maduro';
51 Query OK, 0 rows affected (0.03 sec)
52 Rows matched: 4 Changed: 0 Warnings: 0
53
54 MariaDB [Prueba1]> select * from Est_fruta;
55 +----+----------+--------+
56 | id | nombre | estado |
57 +----+----------+--------+
58 | 1 | Manzanas | Maduro |
59 | 2 | Naranjas | Maduro |
60 | 3 | Uvas | Maduro |
61 | 4 | Platanos | Maduro |
62 +----+----------+--------+
63 4 rows in set (0.00 sec)
64
65 MariaDB [Prueba1]> insert into Est_fruta values ( NULL, 'Sandilla' , 'Maduro' );
66 Query OK, 1 row affected (0.05 sec)
67
68 MariaDB [Prueba1]> select * from Est_fruta;
69 +----+----------+--------+
70 | id | nombre | estado |
71 +----+----------+--------+
72 | 1 | Manzanas | Maduro |
73 | 2 | Naranjas | Maduro |
74 | 3 | Uvas | Maduro |
75 | 4 | Platanos | Maduro |
76 | 5 | Sandilla | Maduro |
77 +----+----------+--------+
78 5 rows in set (0.01 sec)
79
80 MariaDB [Prueba1]> update Est_fruta set nombre = 'Sandia' where nombre = 'Sandilla';
81 Query OK, 1 row affected (0.04 sec)
82 Rows matched: 1 Changed: 1 Warnings: 0
83
84 MariaDB [Prueba1]> select * from Est_fruta;
85 +----+----------+--------+
86 | id | nombre | estado |
87 +----+----------+--------+
88 | 1 | Manzanas | Maduro |
89 | 2 | Naranjas | Maduro |
90 | 3 | Uvas | Maduro |
91 | 4 | Platanos | Maduro |
92 | 5 | Sandia | Maduro |
93 +----+----------+--------+
94 5 rows in set (0.00 sec)
95
96 MariaDB [Prueba1]> create table Inv_fruta ( id int not null primary key auto_increment,
97 -> nombre varchar (50) not null,
98 -> color varchar (15) not null,
99 -> precio float not null,
100 -> cantidad int not null );
101 Query OK, 0 rows affected (0.26 sec)
102
103 MariaDB [Prueba1]> insert into Inv_fruta values ( NULL, 'Manzanas', 'Rojo', 5.0, 25 );
104 Query OK, 1 row affected (0.04 sec)
105
106 MariaDB [Prueba1]> insert into Inv_fruta values ( NULL, 'Naranjas' , 'Anaranja' , 7.5, 44 );
107 Query OK, 1 row affected (0.04 sec)
108
109 MariaDB [Prueba1]> insert into Inv_fruta values ( NULL, 'Uvas' , 'Verde' , 12.5, 15 );
110 Query OK, 1 row affected (0.09 sec)
111
112 MariaDB [Prueba1]> insert into Inv_fruta values ( NULL, 'Platanos' , 'Amarillo' , 1.5, 36 );
113 Query OK, 1 row affected (0.09 sec)
114
115 MariaDB [Prueba1]> select * from Inv_fruta;
116 +----+----------+----------+--------+----------+
117 | id | nombre | color | precio | cantidad |
118 +----+----------+----------+--------+----------+
119 | 1 | Manzanas | Rojo | 5 | 25 |
120 | 2 | Naranjas | Anaranja | 7.5 | 44 |
121 | 3 | Uvas | Verde | 12.5 | 15 |
122 | 4 | Platanos | Amarillo | 1.5 | 36 |
123 +----+----------+----------+--------+----------+
124 4 rows in set (0.00 sec)
125
126 MariaDB [Prueba1]> update Inv_fruta set cantidad = cantidad - 1 where id = 1;
127 Query OK, 1 row affected (0.04 sec)
128 Rows matched: 1 Changed: 1 Warnings: 0
129
130 MariaDB [Prueba1]> select * from Inv_fruta;
131 +----+----------+----------+--------+----------+
132 | id | nombre | color | precio | cantidad |
133 +----+----------+----------+--------+----------+
134 | 1 | Manzanas | Rojo | 5 | 24 |
135 | 2 | Naranjas | Anaranja | 7.5 | 44 |
136 | 3 | Uvas | Verde | 12.5 | 15 |
137 | 4 | Platanos | Amarillo | 1.5 | 36 |
138 +----+----------+----------+--------+----------+
139 4 rows in set (0.00 sec)
140
141 MariaDB [Prueba1]> replace into Inv_fruta values ( 3, 'Uvas', 'Purple', 12.0, 15 );
142 Query OK, 2 rows affected (0.05 sec)
143
144 REPLACE no es ANSI
145
146 MariaDB [Prueba1]> select * from Inv_fruta;
147 +----+----------+----------+--------+----------+
148 | id | nombre | color | precio | cantidad |
149 +----+----------+----------+--------+----------+
150 | 1 | Manzanas | Rojo | 5 | 24 |
151 | 2 | Naranjas | Anaranja | 7.5 | 44 |
152 | 3 | Uvas | Purple | 12 | 15 |
153 | 4 | Platanos | Amarillo | 1.5 | 36 |
154 +----+----------+----------+--------+----------+
155 4 rows in set (0.00 sec)
156
157 MariaDB [Prueba1]> replace into Inv_fruta values ( 5, 'Manzanas', 'Verde', 5.0, 60 );
158 Query OK, 1 row affected (0.04 sec)
159
160 MariaDB [Prueba1]> select * from color;
161 +----+----------+
162 | id | nombre |
163 +----+----------+
164 | 1 | Rojo |
165 | 2 | naranja |
166 | 3 | Purpura |
167 | 4 | Amarillo |
168 +----+----------+
169 4 rows in set (0.00 sec)
170
171 MariaDB [Prueba1]> delete from color;
172 Query OK, 4 rows affected (0.07 sec)
173
174 MariaDB [Prueba1]> select * from color;
175 Empty set (0.00 sec)
176
177 MariaDB [Prueba1]> select * from Est_fruta;
178 +----+----------+--------+
179 | id | nombre | estado |
180 +----+----------+--------+
181 | 1 | Manzanas | Maduro |
182 | 2 | Naranjas | Maduro |
183 | 3 | Uvas | Maduro |
184 | 4 | Platanos | Maduro |
185 | 5 | Sandia | Maduro |
186 +----+----------+--------+
187 5 rows in set (0.00 sec)
188
189 MariaDB [Prueba1]> update Est_fruta set estado = 'Podrido' where id = 3;
190 Query OK, 1 row affected (0.07 sec)
191 Rows matched: 1 Changed: 1 Warnings: 0
192
193 MariaDB [Prueba1]> select * from Est_fruta;
194 +----+----------+---------+
195 | id | nombre | estado |
196 +----+----------+---------+
197 | 1 | Manzanas | Maduro |
198 | 2 | Naranjas | Maduro |
199 | 3 | Uvas | Podrido |
200 | 4 | Platanos | Maduro |
201 | 5 | Sandia | Maduro |
202 +----+----------+---------+
203 5 rows in set (0.00 sec)
204
205 MariaDB [Prueba1]> delete from Est_fruta where estado = 'Podrido';
206 Query OK, 1 row affected (0.03 sec)
207
208 MariaDB [Prueba1]> seMariaDB [Prueba1]> select * from Est_fruta;
209 +----+----------+--------+
210 | id | nombre | estado |
211 +----+----------+--------+
212 | 1 | Manzanas | Maduro |
213 | 2 | Naranjas | Maduro |
214 | 4 | Platanos | Maduro |
215 | 5 | Sandia | Maduro |
216 +----+----------+--------+
217 4 rows in set (0.00 sec)