Last active
December 1, 2023 13:26
-
-
Save felipejoq/cec249cf7f771b674bc3441e35d6a470 to your computer and use it in GitHub Desktop.
SQL - Ayuda memoria general
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- CREA UNA TABLA LLAMADA users | |
CREATE TABLE IF NOT EXISTS "users" ( | |
id SERIAL, | |
name VARCHAR(100) UNIQUE NOT NULL, | |
role VARCHAR(15) NOT NULL, | |
PRIMARY KEY (id) | |
); | |
-- INSERTA REGISTROS EN LA TABLA users | |
INSERT INTO "users" (name, role) VALUES ('Felipe', 'ROLE_ADMIN'); | |
INSERT INTO "users" (name, role) VALUES ('Rodrigo', 'ROLE_USER'); | |
INSERT INTO "users" (name, role) VALUES ('Andrea', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Roberto', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Luis', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Teresa', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Gonzalo', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Andrea', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Yosh', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Ulda', 'ROLE_SELLER'); | |
INSERT INTO "users" (name, role) VALUES ('Renato', 'ROLE_SELLER'); | |
-- ACTUALIZA UN REGISTRO EN LA TABLA users CON ID 3 | |
UPDATE | |
"users" | |
SET | |
"role" = 'ROLE_SELLER' | |
WHERE | |
"id" = 3; | |
-- ACTUALIZA UN REGISTRO EN LA TABLA users CON ROLE MAL ESCRITO | |
UPDATE | |
"users" | |
SET | |
"role" = 'ROLE_SELLER' | |
WHERE | |
"role" = 'ROLE_SELER'; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users | |
SELECT * FROM users; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users CON LIMITE DE 2 | |
SELECT * FROM users LIMIT 2; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users DESPUÉS DEL REGISTRO 2 | |
SELECT * FROM users OFFSET 2; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users CON ROLE "ROLE_ADMIN" | |
SELECT * FROM users WHERE role = 'ROLE_ADMIN'; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users QUE SU NOMBRE COMIENCE CON "R" | |
SELECT * FROM users WHERE "name" LIKE 'R%'; | |
-- SELECCIONA TODOS LOS REGISTROS DE LA TABLA users QUE SU NOMBRE COMIENCE CON "r" | |
SELECT * FROM users WHERE LOWER(name) LIKE LOWER('r%'); | |
-- SELECCIONA TODOS LOS REGISTROS QUE COMIENCEN CON CUALQUIER LETRA Y QUE SIGA UNA 'o' | |
SELECT * FROM users WHERE name LIKE '_o%'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment