Insert, Update, Delete

Introduction to SQL Server

John MacKintosh

Instructor

INSERT

INSERT INTO table_name
INSERT INTO table_name (col1, col2, col3)
INSERT INTO table_name (col1, col2, col3) 
VALUES 
  ('value1', 'value2', value3)
Introduction to SQL Server

INSERT SELECT

INSERT INTO table_name (col1, col2, col3) 
SELECT 
  column1, 
  column2, 
  column3 
FROM other_table 
WHERE 
  -- conditions apply
  • Don't use SELECT *
  • Be specific in case table structure changes
Introduction to SQL Server

UPDATE

UPDATE table 
SET column = value 
WHERE 
  -- Condition(s);
  • Don't forget the WHERE clause!
UPDATE table 
SET 
  column1 = value1, 
  column2 = value2 
WHERE 
  -- Condition(s);
Introduction to SQL Server

DELETE

DELETE 
FROM table 
WHERE 
  -- Conditions
  • Test beforehand!
TRUNCATE TABLE table_name
  • Clears the entire table at once

Introduction to SQL Server

Let's INSERT, UPDATE, and DELETE!

Introduction to SQL Server

Preparing Video For Download...