And the common function MySQL- CRUD

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

  1. Foreign key value table and the value of the field where the foreign key does not match a field into the data. eg: job_idThe table is a foreign key, a value inserted SA_RAPin to job_idthe table's primary key jobsis 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 VALUESspecified null

INSERT INTO departments 
VALUES (300, 'PR', NULL, NULL)

Modify (update) data UPDATE

  • WHEREClause specifies the data to be updated, if omitted WHERERclause, 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

  • WHEREClause specifies the record to be deleted.
DELETE FROM departments
WHERE departments.department_name = 'Finance'

Common Functions

1. Character Functions

Character Functions .png

  • Case-control function
    .Png case-control function

  • Character control function
    Character control function .png

2. Digital function

Rounding, truncating decimal places, modulo
Mathematical Functions .png

3. Date Functions

Gets the current date string into a date, the date is converted to a string
Date function .png

Date functions common format control character
Specifier date functions used .png

Published 32 original articles · won praise 7 · views 7582

Guess you like

Origin blog.csdn.net/Isaacddx/article/details/86634047