These commands used to manage data within schema objects.
1) SELECT
This command is used to retrieve data from the database
Example
SELECT * FROM EMP;
2) INSERT
This command is used to insert data into a table.
Example
To insert into a table with specifying the column name
INSERT INTO T1 (A) VALUES(6);
To insert into a table without specifying the column name
INSERT INTO T1 VALUES(5);
3) UPDATE
This command is used to update data in a table.
Example
To update the entire row in a table
UPDATE T1 SET A=8;
To update a particular row in a table
UPDATE T1 SET A=7 WHERE A=6;
4) DELETE
This command is used to remove one or more rows from a table. It can be rollback.
Example
To delete all rows from a table
DELETE FROM T1;
To delete one row from a table
DELETE FROM T1 WHERE A=4;
5) MERGE
Merge is an update plus insert. It will be updated when it is matched and will be inserted when it is unmatched.
Example
MERGE
INTO T2
USING T1
ON (T1.A = T2.A)
WHEN MATCHED
THEN UPDATE
SET T2.B = T1.B
WHEN NOT MATCHED
THEN
INSERT (T2.A,T2.B) VALUES(T1.A,T1.B);
1) SELECT
This command is used to retrieve data from the database
Example
SELECT * FROM EMP;
2) INSERT
This command is used to insert data into a table.
Example
To insert into a table with specifying the column name
INSERT INTO T1 (A) VALUES(6);
To insert into a table without specifying the column name
INSERT INTO T1 VALUES(5);
3) UPDATE
This command is used to update data in a table.
Example
To update the entire row in a table
UPDATE T1 SET A=8;
To update a particular row in a table
UPDATE T1 SET A=7 WHERE A=6;
4) DELETE
This command is used to remove one or more rows from a table. It can be rollback.
Example
To delete all rows from a table
DELETE FROM T1;
To delete one row from a table
DELETE FROM T1 WHERE A=4;
5) MERGE
Merge is an update plus insert. It will be updated when it is matched and will be inserted when it is unmatched.
Example
MERGE
INTO T2
USING T1
ON (T1.A = T2.A)
WHEN MATCHED
THEN UPDATE
SET T2.B = T1.B
WHEN NOT MATCHED
THEN
INSERT (T2.A,T2.B) VALUES(T1.A,T1.B);
No comments:
Post a Comment