SQL Is Structured Query Language PDF
SQL Is Structured Query Language PDF
1 CREATE TABLE t (
2 id INT PRIMARY KEY,
3 name VARCHAR NOT NULL,
4 price INT DEFAULT 0
5 );
DROP TABLE t ;
1
Add a new column to the table
TRUNCATE TABLE t;
Insert multiple rows into
a table
1
1 INSERT INTO t(column_li
2 st)
3 VALUES (value_list),
(value_list), …;
Insert rows from t2 into
t1
INSERT INTO t1(column_l
1
ist)
2
SELECT column_list
3
FROM t2;
Update new value in the
column c1 for all rows
1 UPDATE t
2 SET c1 = new_value;
Update values in the
column c1, c2 that match
the condition
1 UPDATE
2 SET c1 = new_value,
3 c2 = new_value
4 WHERE condition;
Delete all data in a
table
1 DELETE FROM t;
Delete subset of rows in
a table
1 DELETE FROM t
2 WHERE condition;
Create or modify a
trigger
CREATE OR MODIFY TRIGGE
R trigger_name
1
WHEN EVENT
2
ON table_name TRIGGER_T
3
YPE
4
EXECUTE stored_procedur
e;
WHEN
BEFORE – invoke before
the event occurs
AFTER – invoke after
the event occurs
EVENT
INSERT – invoke for
INSERT
UPDATE – invoke for
UPDATE