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 / natural_join.sql
Created June 11, 2021 19:56
join tables by all columns with the same name.
SELECT city.name, country.name
FROM city
NATURAL JOIN country;
@bartubozkurt
bartubozkurt / insert_into.sql
Created June 12, 2021 21:24
INSERT statement is used to insert a single record or multiple records into a table in SQL Server.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
@bartubozkurt
bartubozkurt / insert_into2.sql
Created June 12, 2021 21:26
If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table.
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
@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');
@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 / 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 / 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 / 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';
DELETE FROM employees
WHERE last_name = ‘Johnson' AND employee_id >= 80;