Insert, Update, Delete

Introduktion till 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)
Introduktion till SQL Server

INSERT SELECT

INSERT INTO table_name (col1, col2, col3) 
SELECT 
  column1, 
  column2, 
  column3 
FROM other_table 
WHERE 
  -- conditions apply
  • Använd inte SELECT *
  • Var specifik om tabellstrukturen ändras
Introduktion till SQL Server

UPDATE

UPDATE table 
SET column = value 
WHERE 
  -- Condition(s);
  • Glöm inte WHERE-satsen!
UPDATE table 
SET 
  column1 = value1, 
  column2 = value2 
WHERE 
  -- Condition(s);
Introduktion till SQL Server

DELETE

DELETE 
FROM table 
WHERE 
  -- Conditions
  • Testa i förväg!
TRUNCATE TABLE table_name
  • Rensar hela tabellen på en gång

Introduktion till SQL Server

Nu kör vi en övning!

Introduktion till SQL Server

Preparing Video For Download...