2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-17 09:25:32 +00:00
cheat.sheets/sheets/_db2/dml
Andres Gomez Casanova 0f69119a48
Update dml
2019-08-05 22:55:13 -05:00

50 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--Insert values on a table
INSERT INTO tbl3 VALUES (2, 'b')
INSERT INTO tbl3 VALUES (3, 'c'), (4, 'd'), (5, 'e') --Atomic
--Insert certain columns
INSERT INTO tbl1 (col1) VALUES (6)
--Insert values from a select
INSERT INTO tbl6 SELECT col1 FROM tbl1
--Insert in temporary table
INSERT INTO session.tmp1 VALUES (1)
--Update fields
UPDATE tbl3 SET col1 = 5, mycol2 = 'e' -all table
UPDATE tbl3 SET col2 = 'd' WHERE col1 = 7
--Merge (upsert)
MERGE INTO tbl3 AS t USING (SELECT col1 FROM tbl1) s ON (t.col1 = s.col1) WHEN MATCHED THEN UPDATE SET col2 = 'X' WHEN NOT MATCHED THEN INSERT VALUES (10, 'X')
--Delete rows
DELETE FROM tbl1 -all table
DELETE FROM tbl1 WHERE col1 > 5
--Export
EXPORT TO myfile OF DEL SELECT * FROM tbl1
--Import
IMPORT FROM myfile OF DEL INSERT INTO mytable1
--Cursor
DECLARE cur1 CURSOR FOR SELECT * FROM tbl1
--Load
LOAD FROM myfile OF DEL INSERT INTO tbl1
LOAD FROM cur1 OF CURSOR INSERT INTO tbl1
--Query the status of the load in a table
LOAD QUERY TABLE tbl1
--Set integrity
SET INTEGRITY FOR tbl1 IMMEDIATE CHECKED
--Ingest
INGEST FROM FILE myfile FORMAT DELIMITED INSERT INTO tbl1
--Get the next value from a sequence
VALUES NEXT VALUE FOR seq
INSERT INTO tbl3 (col1) VALUES (NEXT VALUE FOR seq)