|
¡¡
|
Chapter
5 - Data manipulation
of HYSQL
|
The manipulation of the database record includes insert,update
and delete.
1.
INSERT statement
(1)
Insert a single record into the database
Syntax: INSERT INTO TableName[(FieldName[,FieldName]...)] VALUES (const[,const]...)
When the consts number of VALUES
substatement is equal to the fields number of the table,and that the sequence of
the consts is as same as the sequence of the fields ,the all FieldNames can be
omitted,otherwise they must be listed rightly.
Example 1
To establish a
information department(its DEPTNO is 20):
INSERT INTO DEPT (DEPTNO,DNAME)
VALUES (20,'info-department')
(2)Insert a query result into the database
Syntax:
INSERT
INTO TableName[(FieldName[,FieldName]...)
SELECT subquery
Here the selected fields of
the subquery must correspond with the fields of INTO
substatement.
2. UPDATE statement
Syntax:
UPDATE TableName SET
FieldName=Expression[,FieldName=Expression]...
WHERE FilterCondition
Update records specified by WHERE FilterCondition
in a single table.Therefore WHERE FilterCondition can't
be omitted,otherwise update all records in the table.
Example 2
Arrange Wang as an
operator,and increase his salary 10%:
UPDATE EMP
SET JOB='operator',SAL=SAL*1.1
WHERE ENAME='Wang'
3. DELETE statement
Syntax: DELETE FROM TableName
WHERE FilterCondition
Return
|
¡¡ |