Database (on)

Database (on)

1. Concept

The database is "in accordance with the data structure to organize, warehouse storage and management of." Is a long-term storage in the computer can share an organized, unified management of the collection of large amounts of data.
The database is stored together in a certain way, can be shared with multiple users, with as little redundancy, and application data set independently of each other, can be regarded as electronic file cabinets - place to store electronic files, users can CRUD operations like data file.

2. Why you want to use the database

Summarized in one sentence: it (╯ ▽ ╰) incense ~ ~ it easy to use.

java程序在运行过程中对于数据进行存储操作,数据是保存在内存中的,数据存储是瞬时的,如果发生错误导致程序退出,或者直接退出,都会导致数据丢失并且不可逆。
文件存储数据,xml,Json这个可操作性比较差,不同的文件有不同的解析方式,并且在内存占用和效率问题上很难达到两全程度。

Database can better address these issues

3. Common Database

Oracle, DB2, SQL Server, SQLite (lightweight database), Mysql (free open source)

4. Mysql

Mysql basic operations
  1. Mysql enter in cmd (the premise of all operations, you do not ye come in operation)
    cmd> mysql-uroot--p123456

  2. Operations on the database
    to create database
    create database ccc;

    Create a database procedure modifies the code set
    create database xxx character set gbk;

    View details to create a database of
    show create database xxx;

    Changes to the database code set
    alter database ccc character set gbk;

    Delete the corresponding database
    drop database ccc;

    Choose to use the database
    use xxx;

5. Data Find

  1. Basic query
    query specified field
    select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from t_employees ;

    Discover all
    select * from t_employees;

  2. Query result fields the data calculated
    SELECT the EMPLOYEE_ID, FIRST_NAME, the LAST_NAME, the SALARY * 12 is
    from t_employees;

  3. To re-query - DISTINCT
    the SELECT DISTINCT MANAGER_ID from t_employees;

  4. Alias the
    select EMPLOYEE_ID as 'ID', FIRST_NAME as ' name', LAST_NAME as 'name', SALARY * 12 as 'salary'
    from t_employees;

  5. Sort order by asc (ascending) / desc (descending)
    SELECT from the fieldName tbName Order by the fieldName ASC;

    In descending order according to salary and number of queries
    the SELECT the EMPLOYEE_ID, FIRST_NAME, SALARY
    from t_employees
    the Order by desc SALARY, the EMPLOYEE_ID desc;

  6. where the query
    query in the employee table of contents, wages equal to 11,000 corresponding id number, name, salary, and
    the SELECT the EMPLOYEE_ID, FIRST_NAME, SALARY
    from t_employees
    where SALARY = 11000;

  7. Undefined query symbol
    <less than> greater than <= Less than or equal to> = Greater than or equal! = Not equal (<>)
    equals determination condition where their needs change.

  8. Interval
    between and
    pay 8,000 to 10,000
    SELECT the EMPLOYEE_ID, FIRST_NAME, the SALARY
    from t_employees
    WHERE the SALARY BETWEEN 8000 and 10000;

  9. Enumeration in
    the department number is 60, 70, 90
    the SELECT FIRST_NAME, the DEPARTMENT_ID
    from t_employees
    the WHERE in the DEPARTMENT_ID (70, 60, 90);

  10. Fuzzy queries like
    FIRST_NAME d is contained in a case-insensitive
    SELECT FIRST_NAME
    from t_employees
    WHERE FIRST_NAME like '% D%';

Published 29 original articles · won praise 30 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43932553/article/details/104974941