INSERT, UPDATE, DELETE

Introduction à 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 à SQL Server

INSERT SELECT

INSERT INTO table_name (col1, col2, col3) 
SELECT 
  column1, 
  column2, 
  column3 
FROM other_table 
WHERE 
  -- conditions apply
  • N'utilisez pas SELECT *
  • Soyez précis si la structure de la table change
Introduction à SQL Server

UPDATE

UPDATE table 
SET column = value 
WHERE 
  -- Condition(s);
  • N'oubliez pas la clause WHERE !
UPDATE table 
SET 
  column1 = value1, 
  column2 = value2 
WHERE 
  -- Condition(s);
Introduction à SQL Server

DELETE

DELETE 
FROM table 
WHERE 
  -- Conditions
  • Testez d'abord !
TRUNCATE TABLE table_name
  • Vide toute la table d'un coup

Introduction à SQL Server

Utilisons INSERT, UPDATE et DELETE !

Introduction à SQL Server

Preparing Video For Download...