sql_cheat_sheet
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sql_cheat_sheet [2020/07/06 01:25] – stephen | sql_cheat_sheet [2025/01/13 22:44] (current) – stephen | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== SQL Cheat Sheet ====== | ====== SQL Cheat Sheet ====== | ||
+ | |||
+ | For Postgres SQL, see [[postgres_sql_cheat_sheet|Postgres SQL Cheat Sheet]] | ||
===== CREATE ===== | ===== CREATE ===== | ||
Line 28: | Line 30: | ||
FROM | FROM | ||
Table2 | Table2 | ||
+ | |||
+ | -- INSERTing multiple rows. | ||
+ | INSERT INTO Table1 | ||
+ | (Col1, | ||
+ | VALUES | ||
+ | (Data1, Data2, Data3) | ||
+ | , (Data1, Data2, Data3) | ||
</ | </ | ||
Line 39: | Line 48: | ||
Table1.Col1 = Table2.Col1 | Table1.Col1 = Table2.Col1 | ||
, Table1.Col2 = Table2.Col2 | , Table1.Col2 = Table2.Col2 | ||
+ | FROM | ||
+ | Table1 | ||
+ | INNER JOIN | ||
+ | Table2 | ||
+ | ON | ||
+ | Table2.Id = Table1.Id | ||
+ | </ | ||
+ | |||
+ | ===== DELETE ===== | ||
+ | |||
+ | <code sql> | ||
+ | -- Combining an UPDATE with a JOIN. | ||
+ | DELETE | ||
+ | Table1 | ||
FROM | FROM | ||
Table1 | Table1 | ||
Line 253: | Line 276: | ||
</ | </ | ||
- | ===== Determine the Data Types in Results of a Query===== | + | ===== Determine the Data Types in Results of a Query ===== |
<code sql> | <code sql> | ||
SELECT * FROM sys.dm_exec_describe_first_result_set( | SELECT * FROM sys.dm_exec_describe_first_result_set( | ||
| | ||
+ | </ | ||
+ | |||
+ | ===== Sort out Collation ===== | ||
+ | |||
+ | <code sql> | ||
+ | -- Determine the default collation for the server. | ||
+ | SELECT serverproperty(' | ||
+ | |||
+ | -- Convert a varchar to a specific collation. | ||
+ | SELECT CAST(' | ||
</ | </ | ||
Line 300: | Line 333: | ||
WHERE | WHERE | ||
SourceObjects.object_id IS NULL OR NewObjects.object_id IS NULL | SourceObjects.object_id IS NULL OR NewObjects.object_id IS NULL | ||
+ | </ | ||
+ | |||
+ | ===== Export a .bacpac By Command Line ===== | ||
+ | |||
+ | Install SqlPackage: | ||
+ | < | ||
+ | dotnet tool install -g microsoft.sqlpackage | ||
+ | </ | ||
+ | |||
+ | Export .backpac. Only add the '' | ||
+ | < | ||
+ | SqlPackage / | ||
</ | </ | ||
Line 479: | Line 524: | ||
<code sql> | <code sql> | ||
- | DECLARE @searchText NVARCHAR(MAX) = N' | + | DECLARE @searchText NVARCHAR(20) = N' |
DECLARE @sql NVARCHAR(MAX) = N''; | DECLARE @sql NVARCHAR(MAX) = N''; | ||
sql_cheat_sheet.1593998714.txt.gz · Last modified: 2020/07/07 02:25 (external edit)