Insert data INSERT
1. Insert character and date data
Character and date data should be included in single quotes
INSERT INTO departments (department_id, department_name, manager_id,location_id)
VALUES (280, 'PR', 100, 1700)
possible problems
- Foreign key value table and the value of the field where the foreign key does not match a field into the data.
eg:
job_id
The table is a foreign key, a value insertedSA_RAP
in tojob_id
the table's primary keyjobs
is not present in.
- The exception clause
INSERT INTO
employees(employee_id, last_name, email, hiredate, job_id)
VALUES (302, 'DDX', '[email protected]', STR_TO_DATE('2019-1-1','%Y-%m-%d'), 'SA_RAP')
- Exception information
Cannot add or update a child row: a foreign key constraint fails (`myemployees`.`employees`, CONSTRAINT `job_id_fk` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`job_id`))
2. Insert the null value
Implicit Insert: omitted values for the column name in the list
INSERT INTO departments (department_id, department_name )
VALUES (290, 'PR')
Explicit inserted in VALUES
specified null
INSERT INTO departments
VALUES (300, 'PR', NULL, NULL)
Modify (update) data UPDATE
WHERE
Clause specifies the data to be updated, if omittedWHERER
clause, all data in the table is updated.- A plurality of data can be updated, if prior to roll back the data, the operation is performed to set
SET AUTOCOMMIT = FALSE
.
UPDATE employees
SET department_id = 70
WHERE employee_id = 113
delete data DELETE
WHERE
Clause specifies the record to be deleted.
DELETE FROM departments
WHERE departments.department_name = 'Finance'
Common Functions
1. Character Functions
-
Case-control function
-
Character control function
2. Digital function
Rounding, truncating decimal places, modulo
3. Date Functions
Gets the current date string into a date, the date is converted to a string
Date functions common format control character