03SQL statement

JAVA language database is not know, but we also have to interact with the database, then the database is required to know the language of SQL statements, it is the code of the database.

Structured Query Language (Structured Query Language) referred to as SQL, a database query and programming language for accessing data and query, update and manage a relational database system.

Create a database, create tables, add data to a table of data information is required to use SQL statements.

1.SQL statement

1.1SQL Category:

  • Data Definition Language: Acronym DDL (Data Definition Language), is used to define the database objects: databases, tables, columns and the like. Keywords: create, alter, drop, etc.
  • Data Manipulation Language: Acronym DML (Data Manipulation Language), is used to update the tables in the database records. Keywords: insert, delete, update, etc.
  • Data Control Language: short DCL (Data Control Language), is used to define the level of access and security of the database, and create a user.
  • Data Query Language: short DQL (Data Query Language), used to query the database table records. Keywords: select, from, where, etc.

2. Generic Syntax

  • SQL statements can be single or multiple rows of writing, end with a semicolon
  • You can use spaces and indentation to enhance the readability of the statement
  • MySQL database SQL statements are not case sensitive, it is recommended to use uppercase, for example: SELECT * FROM user.
  • Also you can use / ** / way to complete a comment

We often use the data types of MySQL is as follows

Detailed data types are as follows (not recommended read!)

3. Database Operations

3.1 Creating a database

format:

    * Create database database name;

    * Create database database name of the character set the character set;

E.g:

  # Create a database of encoded data in a database used is specified when you installed the database default encoding utf8

  CREATE DATABASE day21_1;

  # Create a database and specify the encoding of the data in the database

  CREATE DATABASE day21_2 CHARACTER SET utf8;

 

3.2 View database

View all database MySQL database server:

show databases;

View the definition of a database of information:

show create database database name;

E.g:

show create database day21_1;

3.3 Delete Database

drop database database name;

E.g:

drop database day21_2;

3.4 Switching Database

use database name;

E.g:

use day21_1;

3.5 View database being used

select database();

4. The table structure related statements

 4.1 Creating a table

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/xinmomoyan/p/11019813.html