Skip to content

Instantly share code, notes, and snippets.

View bartubozkurt's full-sized avatar
🎯
Focusing

Bartu Bozkurt bartubozkurt

🎯
Focusing
View GitHub Profile
@bartubozkurt
bartubozkurt / update.sql
Created June 13, 2021 08:16
The UPDATE statement is used to modify the existing records in a table.
UPDATE table_name
SET column1 = value1,
column2 = value2, ...
WHERE condition;
@bartubozkurt
bartubozkurt / delete_exist.sql
Created June 12, 2021 21:35
This SQL Server DELETE example would delete all records in the employees table where there is a record in the contacts table whose contact_id is less than 100, and the contact_id matches the employee_id
DELETE FROM employees
WHERE EXISTS
( SELECT *
FROM contacts
WHERE contacts.contact_id = employees.employee_id
AND contacts.contact_id < 100 );
@bartubozkurt
bartubozkurt / delete_top.sql
Created June 12, 2021 21:35
Example would delete the first 3 records from the employees table where the last_name is 'Johnson'.
DELETE TOP (3) FROM Customers WHERE last_name = ‘Johnson’;
@bartubozkurt
bartubozkurt / delete_all.sql
Created June 12, 2021 21:34
delete all table
DELETE FROM Customers;
DELETE FROM employees
WHERE last_name = ‘Johnson' AND employee_id >= 80;
@bartubozkurt
bartubozkurt / delete.sql
Created June 12, 2021 21:32
The DELETE statement is used to delete existing records in a table.
DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';
@bartubozkurt
bartubozkurt / set.sql
Created June 12, 2021 21:32
The SET command is used with UPDATE to specify which columns and values that should be updated in a table.
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
@bartubozkurt
bartubozkurt / insertinto_select_statement.sql
Created June 12, 2021 21:31
You can also create more complicated SQL Server INSERT statements using SELECT statements
INSERT INTO contacts (contact_id, last_name, first_name)
SELECT employee_id, last_name, first_name
FROM employees
WHERE employee_id <= 100;
@bartubozkurt
bartubozkurt / insert_into_multiple_records.sql
Created June 12, 2021 21:29
INSERT statement when inserting multiple records
INSERT INTO Employees (employee_id, last_name, first_name)
VALUES
(10, ‘Bozkurt’,’Bartu’),
(11, ‘Anderson,’Sarah’);
@bartubozkurt
bartubozkurt / specific_insert.sql
Created June 12, 2021 21:28
insert data in specific columns.
INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');