2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-05 12:00:16 +00:00
cheat.sheets/sheets/_db2/dml

50 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-01-07 16:56:47 +00:00
--Insert values on a table
2019-08-06 03:55:13 +00:00
INSERT INTO tbl3 VALUES (2, 'b')
INSERT INTO tbl3 VALUES (3, 'c'), (4, 'd'), (5, 'e') --Atomic
2019-01-07 16:56:47 +00:00
--Insert certain columns
2019-08-06 03:55:13 +00:00
INSERT INTO tbl1 (col1) VALUES (6)
2019-01-07 16:56:47 +00:00
--Insert values from a select
2019-08-06 03:55:13 +00:00
INSERT INTO tbl6 SELECT col1 FROM tbl1
--Insert in temporary table
INSERT INTO session.tmp1 VALUES (1)
2019-01-07 16:56:47 +00:00
--Update fields
2019-08-06 03:55:13 +00:00
UPDATE tbl3 SET col1 = 5, mycol2 = 'e' -all table
UPDATE tbl3 SET col2 = 'd' WHERE col1 = 7
2019-01-07 16:56:47 +00:00
--Merge (upsert)
2019-08-06 03:55:13 +00:00
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')
2019-01-07 16:56:47 +00:00
--Delete rows
2019-08-06 03:55:13 +00:00
DELETE FROM tbl1 -all table
DELETE FROM tbl1 WHERE col1 > 5
2019-01-07 16:56:47 +00:00
--Export
2019-08-06 03:55:13 +00:00
EXPORT TO myfile OF DEL SELECT * FROM tbl1
2019-01-07 16:56:47 +00:00
--Import
IMPORT FROM myfile OF DEL INSERT INTO mytable1
2019-08-06 03:55:13 +00:00
--Cursor
DECLARE cur1 CURSOR FOR SELECT * FROM tbl1
2019-01-07 16:56:47 +00:00
--Load
2019-08-06 03:55:13 +00:00
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
2019-01-07 16:56:47 +00:00
--Set integrity
2019-08-06 03:55:13 +00:00
SET INTEGRITY FOR tbl1 IMMEDIATE CHECKED
2019-01-07 16:56:47 +00:00
--Ingest
2019-08-06 03:55:13 +00:00
INGEST FROM FILE myfile FORMAT DELIMITED INSERT INTO tbl1
2019-01-07 16:56:47 +00:00
--Get the next value from a sequence
2019-08-06 03:55:13 +00:00
VALUES NEXT VALUE FOR seq
INSERT INTO tbl3 (col1) VALUES (NEXT VALUE FOR seq)