You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/dbio/templates/azuresql.yaml
+81-8Lines changed: 81 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
core:
2
-
drop_table: drop table if exists {table}
3
-
drop_view: drop view if exists {view}
2
+
drop_table: IF OBJECT_ID(N'{table}', N'U') IS NOT NULL DROP TABLE {table}
3
+
drop_view: IF OBJECT_ID(N'{view}', N'V') IS NOT NULL DROP VIEW {view}
4
+
drop_index: |
5
+
if exists (
6
+
select name
7
+
from sys.indexes
8
+
where name = '{name}' and object_id = OBJECT_ID('{table}')
9
+
) drop index {index} on {table}
4
10
replace: insert into {table} ({fields}) values ({values}) on conflict ({pk_fields}) do update set {set_fields}
5
11
replace_temp: |
6
12
insert into {table} ({names})
@@ -9,6 +15,12 @@ core:
9
15
update {table} as t1 set {set_fields2}
10
16
from (select * from {temp_table}) as t2
11
17
where {pk_fields_equal}
18
+
limit: select top {limit} {fields} from {table}{where_clause}
19
+
limit_offset: select top {limit} * from ( select {fields} from {table}{where_clause} order by 1 offset {offset} rows) as t
20
+
limit_sql: select top {limit} * from ( {sql} ) as t
21
+
incremental_select_limit: select top {limit} {fields} from {table} where ({incremental_where_cond}){where_and} order by {update_key} asc
22
+
incremental_select_limit_offset: select top {limit} * from ( select {fields} from {table} where ({incremental_where_cond}){where_and} order by {update_key} asc offset {offset} rows) as t
23
+
incremental_select: select {fields} from {table} where ({incremental_where_cond}){where_and}
12
24
insert: insert into {table} ({fields}) values ({values})
13
25
insert_temp: insert into {table} ({fields}) select {cols} from {temp_table}
14
26
insert_ignore: insert into {table} ({fields}) values ({values}) on conflict ({pk_fields}) do nothing
@@ -20,11 +32,6 @@ core:
20
32
sample: select {fields} from {table} TABLESAMPLE SYSTEM (50) limit {n}
21
33
rename_table: ALTER TABLE {table} RENAME TO {new_table}
limit: select top {limit} {fields} from {table}{where_clause}
24
-
limit_offset: select top {limit} * from ( select {fields} from {table}{where_clause} order by 1 offset {offset} rows) as t
25
-
limit_sql: select top {limit} * from ( {sql} ) as t
26
-
incremental_select_limit: select top {limit} {fields} from {table} where ({incremental_where_cond}){where_and} order by {update_key} asc
27
-
incremental_select_limit_offset: select top {limit} * from ( select {fields} from {table} where ({incremental_where_cond}){where_and} order by {update_key} asc offset {offset} rows) as t
28
35
bulk_insert: |
29
36
BULK INSERT {table}
30
37
from '/dev/stdin'
@@ -37,6 +44,36 @@ core:
37
44
)
38
45
column_names: '{sql}'
39
46
add_column: alter table {table} add {column} {type}
47
+
alter_columns: alter table {table} alter column {col_ddl}
48
+
modify_column: '{column} {type}'
49
+
50
+
# SQL Server supports all 4 merge strategies
51
+
merge_insert: |
52
+
INSERT INTO {tgt_table} ({insert_fields})
53
+
SELECT {src_fields} FROM {src_table} src
54
+
55
+
merge_update: |
56
+
UPDATE tgt
57
+
SET {set_fields}
58
+
FROM {tgt_table} tgt
59
+
INNER JOIN {src_table} src
60
+
ON {src_tgt_pk_equal}
61
+
62
+
merge_update_insert: |
63
+
MERGE INTO {tgt_table} tgt
64
+
USING (SELECT {src_fields} FROM {src_table}) src
65
+
ON ({src_tgt_pk_equal})
66
+
WHEN MATCHED THEN UPDATE SET {set_fields}
67
+
WHEN NOT MATCHED THEN INSERT ({insert_fields}) VALUES ({src_insert_fields});
0 commit comments