No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Aprende Ingl茅s, Programaci贸n, AI, Ciberseguridad y mucho m谩s.

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

4 D铆as
20 Hrs
55 Min
46 Seg

Playground: INSERT, UPDATE y DELETE en SQL

18/34

Aportes 27

Preguntas 0

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

Me encanta que hayan incluido los playgrounds. Son sumamente dinamicos y te insita a practicar lo estudiado,

Mi solucion.

INSERT INTO lines (id, name, color)
VALUES (7, 'Nueva Linea 7', 'Naranja');

UPDATE lines
SET name = 'Linea 1'
WHERE id = 1;

DELETE FROM lines
WHERE id = 5;

SELECT * FROM lines;
Spoiler . . . . . . . . . . . . . . . ![](https://static.platzi.com/media/user_upload/image-d9f1e58f-f01e-48c9-9660-92e540ec140a.jpg)
```js SELECT * FROM lines; INSERT INTO `lines` (id,name,color) VALUES (7, "Nueva Linea 7", "Naranja"); UPDATE `lines` SET name = "Linea 1" WHERE id = 1; DELETE FROM `lines` WHERE id=5; SELECT * FROM `lines`; ```

Les comparto mi soluci贸n y aprovecho para hacer una pregunta,

  1. 驴El SET como se interpreta en el ejercicio de actualizaci贸n ?
INSERT INTO 
`lines` (
  `id`, `name`, `color`
  ) 
VALUES 
(7, "Nueva Linea 7", "Naranja");

UPDATE `lines`
SET `name` = "Linea 1"
WHERE `id` = 1;  

DELETE FROM `lines`
WHERE `id` = 5;
\-- Escribe tu c贸digo aqu铆 馃憞SELECT \* FROM lines; \--crear nuevo registro de lineaINSERT INTO `lines` (id,name,color) VALUES(7,"Nueva Linea 7", "Naranja"); \--Actualizar el registro de la linea 1UPDATE `lines` SET 聽name = 'Linea 1'WHERE id = 1; \--Eliminar el registro de la linea de id 5DELETE FROM `lines`WHERE id = 5; SELECT \* FROM lines;
SELECT \* FROM lines; INSERT INTO lines (id, name, color)VALUES (7, 'Nueva Linea 7', 'Naranja'); UPDATE linesSET name = 'Linea 1'WHERE id = 1; DELETE FROM linesWHERE id = 5;
Soluci贸n al problema: ```js --Query table SELECT * FROM lines; --Resolving problem one (insert data) INSERT INTO lines (id, name, color) VALUES (7, 'Nueva Linea 7','Naranja'); --Resolving problem two (update data) UPDATE lines SET name = 'Linea 1' WHERE id = 1; --Resolving problem three (delete data) DELETE FROM lines WHERE id = 5; --Query table (test) SELECT * FROM lines; ```
\-- Escribe tu c贸digo aqu铆 馃憞 SELECT \* FROM lines;INSERT INTO `lines` (id, name, color) VALUES(7,"Nueva Linea 7" ,"Naranja"); SELECT \* FROM lines; UPDATE `lines`SET name="Linea 1"WHERE id=1; SELECT \* FROM lines; DELETE FROM `lines`WHERE id=5; SELECT \* FROM lines;

Recuerden comentar con puntos para que no se vea inmediatamente la respuesta, puesto que espoilea a los que vienen a hacer el ejercicio
.
.
.
.
.

INSERT INTO `lines` (id, name, color) VALUES
(7, "Nueva Linea 7", "Naranja");

UPDATE `lines`
SET name = "Linea 1"
WHERE id = 1;

DELETE FROM `lines`
WHERE id = 5;

SELECT * FROM lines;
insert into `lines`(id,name,color)
values(7,"Linea A-20","Rosa");

como sugerencia debieron codificar el id de la tabla de prueba con el constraint AUTO INCREMENT como en las clases
perdi un par de intentos porque estaba omitiendo el id pensando que no era necesario

Excelente pr谩ctica!

.
.
.
.
.
.
.
.
.
.
.
.
.

-- INSERT
INSERT INTO lines (id, name, color)
VALUES (7, 'Nueva Linea 7', 'Naranja');

-- UPDATE
UPDATE lines
SET name = 'Linea 1'
WHERE id = 1;

-- DELETE
DELETE FROM lines
WHERE id = 5;

SELECT * FROM lines;

Facil

-- Escribe tu c贸digo aqu铆 馃憞
INSERT INTO lines(id,name, color)
VALUES(7,'Nueva Linea 7','Naranja');

UPDATE `lines`
SET name='Linea 1' WHERE id=1;

DELETE FROM `Lines`
WHERE id = 5;
SELECT * FROM lines;
SELECT * FROM lines;

INSERT INTO `lines` (id,name,color) VALUES
(7,'Nueva Linea 7', 'Naranja');

UPDATE `lines`
SET name = 'Linea 1'
WHERE id = 1;

DELETE FROM `lines`
WHERE id = 5;

Si se pudo:

-- Escribe tu c贸digo aqu铆 馃憞
INSERT INTO lines (id, name, color) VALUES
(7, "Nueva Linea 7", "Naranja");

UPDATE `lines`
SET name = "Linea 1"
WHERE id = 1;

DELETE FROM `lines`
WHERE id = 5;

-- SELECT * FROM lines;
-- Escribe tu c贸digo aqu铆 馃憞
SELECT * FROM lines;

INSERT INTO `lines` (id, name, color) VALUES
(7, "Nueva Linea 7", "Naranja");

UPDATE `lines`
SET name = "Linea 1"
WHERE id = 1;

DELETE FROM `lines`
WHERE id = 5;

鈥 Escribe tu c贸digo aqu铆 馃憞

<SELECT * FROM lines;
INSERT INTO lines (id,name,color)
VALUES (7,"Nueva Linea 7","Naranja")
;
UPDATE lines SET name = "Linea1"
WHERE id in (1);

DELETE FROM lines WHERE id in (5);> 

Esta es mi solucion

insert into lines (name, color) values ('Nueva Linea 7','naranja');
update lines set name ='Linea 1' where id = 1;
delete from lines where id = 5;

pero el editor me arroja un error.

(SQL error) NOT NULL constraint failed: lines.id

y entiendo que es porque me esta pidiendo que incorpore el ID en el Insert de la siguiente forma

insert into lines (id, name, color) values (7,'Nueva Linea 7','naranja');

pero si el ID es un autoincremental, no encuentro que sea buena practica el 鈥淢anipular鈥 el campo, ya que queda a mi responsabilidad que el ID se el numero que sigue, pero que pasa si al manipular el valor, me 鈥渟alto鈥 varios numeros? o reutilizo uno que elimine?, desde mi punto de vista los valores autoincrementales NO SE MANIPULAN.

Mi solucion:

-- Escribe tu c贸digo aqu铆 馃憞
SELECT * FROM lines;

INSERT INTO lines (id,name,color) VALUES(7,"Nueva Linea 7","Naranja");


UPDATE lines
SET name="Linea 1"
WHERE id=1;

DELETE FROM lines
WHERE id=5;

隆Me encantan estos ejercicios!

INSERT INTO lines (id,name,color)
VALUES
  ('7','Nueva Linea 7','Naranja');

UPDATE lines
SET name = 'Linea 1' WHERE id = 1;

DELETE FROM lines
WHERE id = 5;

SELECT * FROM lines;

馃榾

鈥 Escribe tu c贸digo aqu铆 馃憞
SELECT * FROM lines;

INSERT INTO lines (id, name, color) VALUES
( 7, 鈥淣ueva Linea 7鈥, 鈥淣aranja鈥);

SELECT * FROM lines;

UPDATE lines
SET name = "Linea 1"
WHERE id = 1;

SELECT * FROM lines;

DELETE FROM lines
WHERE id = 5;

SELECT * FROM lines;

Mi soluci贸n:

-- INSERTAR NUEVO REGISTRO
INSERT INTO `lines` (id, name, color) VALUES
(7, "Nueva Linea 7", "Naranja");

-- ACTUALIZAR EL REGISTRO DE LA L脥NEA CON ID 1
UPDATE `lines`
SET name = "Linea 1"
WHERE id = 1;

-- ELIMINAR EL REGISTRO DE LA L脥NEA CON ID 5
DELETE FROM `lines` WHERE id = 5;

Hola , les comparto mi soluci贸n:

INSERT INTO lines (id, name, color) VALUES
(鈥7鈥, 鈥淣ueva Linea 7鈥, 鈥淣aranja鈥);

UPDATE lines
SET name = "Linea 1"
WHERE id = 1;

DELETE FROM lines
WHERE id = 5;

鈥 Escribe tu c贸digo aqu铆 馃憞
SELECT * FROM lines;

undefined