Snowflake SQL Tutorial: Deleting Rows with Precision

Опубликовано: 09 Ноябрь 2025
на канале: Data World Solution
438
6

Unlock the power of Snowflake's DELETE command! Master data management with efficient record deletion for a cleaner, optimized database

-----------------------------------------
-- DELETE
-- TO DELETE THE DATA FROM TABLE




CREATE OR REPLACE TABLE employees (
id INT,
name VARCHAR(100),
department VARCHAR(100),
salary DECIMAL(10, 2)
);

INSERT INTO employees (id, name, department, salary)
VALUES
(1, 'John Doe', 'HR', 50000.00),
(2, 'Jane Smith', 'IT', 60000.00),
(3, 'Michael Johnson', 'HR', 55000.00),
(4, 'Emily Davis', 'Finance', 70000.00),
(5, 'David Brown', 'IT', 62000.00),
(6, 'Sarah Wilson', 'HR', 51000.00),
(7, 'James Taylor', 'Finance', 72000.00),
(8, 'Emma Martinez', 'IT', 59000.00),
(9, 'Matthew Anderson', 'HR', 53000.00),
(10, 'Olivia Thomas', 'Finance', 75000.00),
(11, 'William White', 'IT', 63000.00),
(12, 'Sophia Rodriguez', 'HR', 52000.00),
(13, 'Daniel Garcia', 'Finance', 71000.00),
(14, 'Isabella Lopez', 'IT', 61000.00),
(15, 'Alexander Hernandez', 'HR', 54000.00),
(16, 'Mia Gonzalez', 'Finance', 74000.00),
(17, 'Ethan Wilson', 'IT', 58000.00),
(18, 'Ava Perez', 'HR', 56000.00),
(19, 'Liam Turner', 'Finance', 73000.00),
(20, 'Charlotte Flores', 'IT', 60000.00),
(21, 'Noah Sanchez', 'HR', 57000.00),
(22, 'Amelia Torres', 'Finance', 76000.00),
(23, 'Benjamin Ramirez', 'IT', 64000.00),
(24, 'Harper Rivera', 'HR', 55000.00),
(25, 'Elijah Cruz', 'Finance', 77000.00);


select * from employees;

SELECT * FROM EMPLOYEES WHERE department = 'HR';

DELETE FROM employees
WHERE department = 'HR';

-- Delete employees with a salary less than $60,000.
SELECT * FROM EMPLOYEES WHERE salary lees than 60000;

DELETE FROM employees
WHERE salary less than 60000;




DELETE FROM employees
WHERE ID IN (SELECT ID FROM EMPLOYEES WHERE DEPARTMENT = 'IT');


DELETE FROM EMPLOYEES;

TRUNCATE TABLE EMPLOYEES;


------------
#SnowflakeSQL #DataManagement #DeleteCommand #SQLCommands #sql