Skip to content

Commit 68953a4

Browse files
committed
Add trigger to autopopulate primary key on insert
1 parent 204bc98 commit 68953a4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/schema/sqlserver_specific_schema.rb

+15
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@
266266
SELECT pk_col_one AS id_source, event_name FROM INSERTED
267267
SQL
268268

269+
270+
execute <<-SQL
271+
CREATE TRIGGER instead_of_insert_trigger
272+
ON pk_autopopulated_by_a_trigger_records
273+
INSTEAD OF INSERT
274+
AS
275+
BEGIN
276+
INSERT INTO pk_autopopulated_by_a_trigger_records (
277+
[id]
278+
)
279+
SELECT ((COALESCE(MAX(pk_autopopulated_by_a_trigger_records.id), 0) + 1))
280+
FROM pk_autopopulated_by_a_trigger_records
281+
END
282+
SQL
283+
269284
# Another schema.
270285

271286
create_table :sst_schema_columns, force: true do |t|

0 commit comments

Comments
 (0)