Java Knowledge Summary-3

Source: Internet
Author: User

Database Operation language
Tags: command is case-insensitive but cannot use Chinese space punctuation, etc.
Classification

Data Query Language DQL

Data Definition Language DDL

Data Manipulation Language DML

Knowledge of database theory

relational database

MySQL Default Port 3306

Db2

Oracle Default Port

Object-oriented database is a new type of database which is produced by object-oriented programming language, relational database is the most mature and widely used database, the most basic data storage unit is data table, data table is the logical unit of storing data, can think of data table as a table composed of rows and columns, each line is also called a record , each column is also called a field

Databases (database, abbreviated as DB): Warehouses that organize, store, and manage data in accordance with its data structure

A warehouse that organizes, stores, and manages data in accordance with its data structure

Database Management System (DBMS): A knowledge base for all data that manages the storage, security, consistency, concurrency, recovery, and access of data There is a data dictionary (sometimes called a system table) that stores information about each transaction it owns, such as the name, structure, location type, which is also known as metadata

History: Network------------relational--object oriented

Data: A symbolic representation of an objective thing, a basic object stored in a database

Category: Text, graphics, images, sounds

Operations on a database

Show show databases;

Set names GBK--setting the encoding before building the table

CREATE DATABASE name----

Drop database name-------Delete databases

Use database name------Enter database

Operations on a table

Creation of tables

CREATE table name (column name type (length), ..... )------Create a table

CREATE Table table name (Type of column list, type of column name, type of column name,..............); Example: CREATE TABLE XS (XH VARCHAR), XM CHAR (8), JS int, LL INTEGER, WH int);

Constraints on Columns

The overall structure of the CREATE table table name (column list type constraint, column list type constraint, ...). );----------------constraints when creating a table
Tags: multiple constraints can exist on one column at a time

ALTER TABLE FILE ADD CONSTRAINT FOREIGN KEY (FILEID) REFERENCES FOLDER (FID) on DELETE CASCADE;

FOREIGN KEY constraints
FOREIGN key (foreign key column name for this table) REFERENCES other table names (primary key column names for other tables)-----------reduce redundant information
Tags: write after all attributes separated by commas

CREATE TABLE XS1
(
Study number varchar (6) NULL,
Name varchar (8) Not NULL,
Date of birth datetime NULL,
PRIMARY KEY (name),,
FOREIGN key (foreign key column name for this table)
REFERENCES Other table names (primary key column names for other tables)
On DELETE Restrict/cascade
On UPDATE Restrict/cascade
);

On delete cascade/on update cascade
Tags: delete/modify cascade that automatically changes if the data associated with the foreign key changes

On delete restrict/on update restrict
Tags: Deleting a modification constraint cannot modify the primary key associated with a foreign key

Check specified value constraint MySQL temporarily not supported

Self-auto_increment is typically added to the primary key column column when the table is built (only the unique ability to self-grow)

Unique constraint

Unique

Primary key does not need to join a unique constraint

CREATE TABLE XS1
(
Study number varchar (6) NULL,
Name varchar (8) Not NULL,
Date of birth datetime NULL,
PRIMARY KEY (School number),
UNIQUE (name)
);

Non-null constraint
Tags: any column can

NOT NULL----

CREATE TABLE student (no int primary key, name varchar (TEN) NOT null Unique,sex char (2));

PRIMARY KEY constraint
Tags: only one on a table can have a composite primary key

Primary KEY-----

CREATE TABLE student (no int primary key, name varchar (TEN) not Null,sex char (2));
CREATE TABLE student (no int primary key, name varchar (TEN) not Null,sex char (2) null);

Type of column

Char---Character one Kanji account two bytes

Date---Format: 2016-1-4

Datatime Time and date combination

Blob binary data

int---Number can specify length

Time---The format of 12:02:45

varchar----string occupancy length + 1 bytes

Operations on a table

Show tables-----display all the tables

Change name

ALTER TABLE name Rename the name of the new table name------change tables

Rename table table name to new name

DROP table name------Delete Tables

DESC Table name-----display table Structure

Table structure modification actions on a column

Delete Column

ALTER TABLE Name drop column type-----Delete Column

ALTER TABLE XS DROP PRIMARY KEY; Delete a primary key from a table

Add columns

ALTER TABLE name add column list type after column name 3-----Add a column behind column 3

ALTER TABLE name add column list type-------add a new column in the last column

ALTER TABLE name add column name first---Add a column in column one

modifying columns

ALTER TABLE table name modify column Name column type--------Modify column data type
Tags: only column types can be modified

ALTER TABLE name change column name new column list type
Tags: modifying column names and column types at the same time

ALTER TABLE XS1 Change XH xh1 varchar (n) primary key; Modify the name and type of a column

Change the name of a table

ALTER TABLE name modify column Name column type------Change the data type of the class

ALTER TABLE name change original column name new column type--------changing the data type of a class

Where to use

Between value 1 and value 2-----between value 1 and value 2

RegExp Regular expression matching

And-and-and-or-or is null empty is not NULL = equal to <> not equal! = Not equal to < less than > greater than

Operations on the data

Add data

Insert into table name set column name = data, column name = data ...----------insert part of the data

Insert into table name (column name 1, column Name 2 ...) Values (data 1, Data 2 ...). )---------Insert part of the data (the data listed in parentheses behind the table name)

Insert into table name (insert data by column order and type)------inserting data (all must be inserted)

Date

Now/sysdate Current Date-----Returns the current date and time

Curtime---return current time

Curdate/current Date Current

Delete data
Tag: Delete a row in a list

Delete from table name---------Remove all data from table

TRUNCATE TABLE indicates that-------Delete all data in the table and reset the primary key

Delete from table name where column name = column value--------Delete qualified data

Example: DELETE from LOGIN WHERE name= ' Wangwu '
DELETE from LOGIN WHERE name= ' Zhangsan ' OR pass= ' 123 ';
DELETE from LOGIN WHERE name= ' Zhangsan ' and pass= ' 123 '; Row deletion with conditions

modifying data

Update table name set column name = column value where specify criteria-----update data that matches the specified criteria if there are no conditions then change all values

UPDATE T3 SET name= ' Zhangsan '; All the name columns become Zhangsan
UPDATE T3 SET name= ' LISI ' WHERE ID = 2;

View data

SELECT * FROM table name where condition-----Search by condition

SELECT * FROM table name------View all information for the table

Find data and actions by criteria

DISTINCT--------Remove Duplicate data

SELECT DISTINCT column name from BOOKS;

In determines a collection (that is, only the contents of the collection)

WHERE (between and, and OR is null are NOT NULL, > < =! = ...). In OK Collection)
In determines that a collection is not in


Select name from the book where ID in (125,127,129,131);

Column from table name of the SELECT query the Where condition-----display only the specified column in the found result


SELECT Name,price from BOOKS;

As Alias

SELECT column name as Alias from BOOKS;

You can use it behind the have.

Like fuzzy query _ single character% 0 or more characters

Having----is equivalent to where it can only be used after grouping as a judgment

Order BY column name DESC/ASC----in descending/ascending order by column name

SELECT * from BOOKS ORDER by pubdate Desc


SELECT * from BOOKS ORDER by price desc, num ASC;
Tags: first column first row when the first column is the same as the second row and so on

A subquery------that finds the query result as a parameter of another query nested
Tag: If the return is a table, you need to have an alias (subquery result) in the back of the table. A is an alias

Aggregation functions
Tags: results can be used as a single parameter

Max---max value

Min-----Minimum value

AVG-----Average

Count----rows

Sum-----sum

Correlation Query

Internal connection

Show only the intersection of the tables and display only the information in the two table

SELECT * FROM table 1 inner JOIN table 2 on table name. column name = table name. Column Name

The final must be the same column as the table

Right connection

Displays all information on the table to the left of the join statement plus the intersection information for the right table is not displayed as null

SELECT * FROM table 1 left JOIN table 2 on table name. column name = table name. Column Name

The final must be the same column as the table

Left connection

Displays all information for the table that is located on the right side of the join statement plus the intersection information for the left table is not displayed as null

SELECT * FROM table 1 Right Join table 2 on table 1. Column name = table 2 name. Column Name

Group

Limit 5/limit 5,6----pagination The first number starts with the ordinal second data offset

Table name Group BY column name------grouped by column name

SELECT NOTE, AVG (price) from BOOKS GROUP by NOTE;

Note that the columns following group by groups can appear after select,
Other columns appear meaningless. Aggregate functions are often used in conjunction with GROUP by

The order of statements for select Lookup [can be omitted]

Java Knowledge Summary-3

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.