The Java self-study road-DAY18

Source: Internet
Author: User

Database

Database Concepts

L Modify one of the data for a series of data

L If I use IO stream, I need to read and write and then find one row to modify.

L or use an array to modify

L This is too complex and inefficient so you need to reference the database

Database essence is a file system that can be seen as a container with good data handling capabilities and an array of collections.

l have a strict data storage format inside.

L Database management System is a software management database

L Common Database management system

    1. MYSQL Open Source free Swedish company Development Sun Company acquisition Oracle acquisition of Sun Mysql6.x after charging small and medium-sized enterprises use
    2. Oracle Billing database Oracle Company products for large companies using
    3. DB2 IBM fees are commonly used in the banking system
    4. SQL Server Microsoft Corporation charges C #. NET Language Usage
    5. Sybase has faded out of the historical stage provides a professional data modeling tool PowerDesigner
    6. SQLite embedded database is used on the mobile phone side
    7. Java is commonly used for MYSQL and Oracle, and others can also be used
Database and Management Systems

• There can be multiple database databases in MySQL where the data is actually stored

L The relationship between the two

    1. Client facing database management system
    2. Database management System Operations database
    3. Database Operations Table

• MySQL database is a repository of server storage databases

MySQL database has a lot of database MySQL database is a generic term

l need to create your own database to use the database

The data stored in the database must be stored in the table.

Database tables

L store data in tables in a database

L table appears in Java class

L table fields are similar to properties in a class

Every piece of data in a table is similar to an object

L Figure

Table Data

L User Table

L Each table indicates that every thing is a class

Each column represents each property in a class

L Each row is a data representation of every object in a class

MySQL database installation MySQL
    1. Charges after mysql6.x
    2. Double-click the 5.5 installation package next
    3. Choosing a Custom Installation
    4. Manually select the installation location
    5. Two installation paths

A) MYSQL Server

b) Server data files

    1. Click on next to install the
    2. Click Next again when you are finished installing
    3. Then tick the lanch ... Run the Configuration Wizard
    4. Click Finish to do it.
    5. Start Configuration Wizard
    6. Select the first fine configuration
    7. Select the first developer PC
    8. Select the first multi-function database
    9. MySQL engine storage location do not change
    10. Select the third maximum number of custom connections
    11. Enable TCP/IP network protocol default port number
    12. Select a third default character set to change to Utf-8
    13. Install Windows service called MySQL

Import Environment variables

    1. Set Password
    2. Click Execute
    3. Installation Complete
    4. There is a MySQL service in Windows service that can stop or turn on the service and turn it on automatically or manually
    5. 360 network connection or the MySQL service program appears
    6. Command line open Service
MySQL in the system service

MySQL Login

l command line-typed mysql–uroot–p123

L Account number and password

L can also write accounts and passwords separately

L Login Successful

L Bad Password

L Account Error

SQLyog

L Graphical Development tools

L Free Installation

SQL language Overview

Database cannot be in the Java language

L SQL statement to use database to interact with database

L is the code in the database

L is a database query and programming language

L for accessing data queries, updating and managing relational database systems

L CREATE database Create data table add data information to a database requires the use of SQL statements

L applies to all databases

SQL statements

L Data Definition Language DDL

Define database object database tables, columns

Keyword creat alter drop create modify Delete

L Data Manipulation Language DML

Update operations on database data

Keyword Insert Delete update

L Data Control Language DCL

For assigning access and security levels, you can also create users

L Data Query Language DQL

Used to query the records that the database has won

Keyword SELECT from where

SQL General Syntax

The SQL statement can be written as a single line or multiple lines with a semicolon ending

L can use spaces or indents to enhance the readability of the statement

L Case insensitive

L can use/**/to annotate

L Data type

    1. Int
    2. Double
    3. varchar variable character
    4. Date type is only a month and a day no time or seconds
    5. There's a lot of other
Database operations

L Create a database

Create Dataabase database name;

Create database name character set character set;

The character set is not specified because the default character set is changed during installation

L Display Database

show databases;

L Delete a database

drop database name;

L Operation No Confirmation

CREATE TABLE Actions

L format

L Constraints

Restrict what data the column names write

    1. PRIMARY KEY constraint
    2. Non-null constraint
    3. Unique constraint
    4. FOREIGN KEY constraints
Saving of SQL code

L can save normally ctrl+s

l file suffix. sql

L text File

L Import

Ctrl+o

Create a presentation example

L Figure

PRIMARY KEY constraint

L Only non-empty

L do not have any meaning only to identify the life is not the only system has

L Add this keyword after the private key column

L Specify the primary key primary key (ID) at the end of the table

L Auto_increment enables automatic growth of primary keys to ensure uniqueness and non-nullability

L View Table

Show Table name View all tables

DESC Table name View table structure

L Delete a table

DROP table Name

Modify Table Structure

L Add columns

    1. Alter table name add column name data type constraint

L Modify Columns

    1. Type modification to note
    2. Alter table table name modify column name data type constraint

L Modify Column names

    1. Alter table name change old column name new column name data type constraint

L Delete Columns

    1. Alter table Name drop column name

L Modify Table name

    1. Rename table name to new name

L Modify the table character set

Alter table name Character Set character set

Data Table Add data

L Insert into table name (column name 1, column name 2, column name 3) VALUES (value 1, value 2, value 3)

    1. Note the Column Name Table name problem don't write wrong
    2. Corresponding problem column and the number of values to correspond
    3. No string concept characters are enclosed in single quotes '
    4. Numbers can be without single quotation marks

L Insert into table name (column name) values (value)

    1. No primary key
    2. Column names do not write primary key values and do not write primary keys

L Insert into table name values (value)

    1. All values are given
    2. Do not write column names
    3. But the value must be written enough

L Bulk Write

L Insert into table name (column name 1, column name 2, column name 3) VALUES (value 1, value 2, value 3), (value 1, value 2, value 3), (value 1, value 2, value 3),

    1. Bulk Write Data
    2. Value Write multiple

If you delete an auto-incrementing ID in the software, add one, and the ID is automatically incremented based on the deleted ID.

Update data

L Update table name set column 1= value 1, column 2= value 2 where condition

    1. Condition ID
    2. The wording of the condition

equals = less than < greater than > less than or equal to <=

With or not, and or not

Id in (1,3,4,5) contains

Id not IN (1) does not contain

Delete data

L Delete from table name where condition

    1. Do not empty one piece of delete does not empty auto_increment record number The next increase will continue to increment on the original basis

L Truncate Table table name destroy tables

    1. Delete a table directly
    2. Re-build the table
    3. Auto_increment will be set to 0 new start

L Query the contents of the table

L MySQL encoding mode is UTF-8 Windows is GBK so will appear Chinese garbled

L Change the encoding of the specified column

L Other

Data query data sheet and test data preparation

Basic Query

L Query the data of the specified column

Select column name 1, column name 2 from table name

L Query All columns

Select * FROM table name

L Remove Duplicate records

Select disctinct column name from table name

L Query and temporarily rename the name of the column

Select column name as ' name to modify ' from table name

Name after add as modified

Or just add the modified name.

L Direct Operations in queries

    1. Select Column name operator number as ' from table name
    2. Add as is because the column name changes after the operation.

Conditional query

L SATISFY the condition query does not satisfy the operation

L Comparison Operators

L Logical operators

L query data for a given name

L Greater than

L and

L Between and

L Or

L in

L Like Fuzzy query

    1. Start with millet

    1. There are millet at the beginning.

    1. Query several characters with a few underscores to represent several characters

L The query is not empty

Sort queries

L Ascending

Select * FROM table name order BY column name ASC

ASC can not write

L Descending

Select * FROM table name order BY column name Desc

L QUERY the specified column in descending order

Unable to sort results in Chinese is unpredictable

Aggregation function query (portrait query) concept

L was a horizontal query before.

L sometimes need to calculate a longitudinal query

L need to use an aggregate function to calculate each column and return a single value

Example

L Count

L Sum

L AVG

L Max min

L Mixed calculation

L Group Query

    1. Grouping repeating content separately for aggregation calculations

    1. Filter PName

    1. Filter PName

    1. Filter sum

Having to filter after grouping

Cannot use where after grouping

Command line garbled problem

The Java self-study road-DAY18

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.