数据操作命令用于操作数据库中的数据。
一些数据操作命令是-
Select语句根据旁边指定的约束条件从数据库检索数据。
SELECT <COLUMN NAME> FROM <TABLE NAME> WHERE <CONDITION> GROUP BY <COLUMN LIST> HAVING <CRITERIA FOR FUNCTION RESULTS> ORDER BY <COLUMN LIST>
通用语法-
示例:从雇员中选择*,其中e_id> 100;
Insert语句用于将数据插入数据库表。
通用语法-
INSERT INTO <TABLE NAME> (<COLUMNS TO INSERT>) VALUES (<VALUES TO INSERT>)
示例:将值('ABC',3)插入到Employee(名称,dept_id)中;
update命令更新表中的现有数据。
通用语法-
UPDATE <TABLE NAME> SET <COLUMN NAME> = <UPDATED COLUMN VALUE>, <COLUMN NAME> = <UPDATED COLUMN VALUE>, <COLUMN NAME> = <UPDATED COLUMN VALUE>,… WHERE <CONDITION>
例如:update Employee set Name ='AMIT'其中E_id = 5;
根据给定的约束从数据库表中删除记录。
通用语法-
DELETE FROM <TABLE NAME> WHERE <CONDITION>
示例-
delete from Employee where e_id=5;
要删除表中的所有记录-
Delete * from <TABLE NAME>;
使用MERGE语句从一个表中选择行以进行更新或插入到另一个表中。根据ON子句中的条件决定是更新还是插入目标表。它也被称为UPSERT,即UPDATE和INSERT的组合。
通用语法(SQL)-
MERGE <TARGET TABLE> [AS TARGET] USING <SOURCE TABLE> [AS SOURCE] ON <SEARCH CONDITION> [WHEN MATCHED THEN <MERGE MATCHED > ] [WHEN NOT MATCHED [BY TARGET] THEN < MERGE NOT MATCHED >] [WHEN NOT MATCHED BY SOURCE THEN <MERGE MATCHED >];
通用语法(Oracle)
MERGE INTO <TARGET TABLE> USING <SOURCE TABLE> ON <SEARCH CONDITION> [WHEN MATCHED THEN <MERGE MATCHED > ] [WHEN NOT MATCHED THEN < MERGE NOT MATCHED > ];