Basic SQL statements

Source: Internet
Author: User

There are 3 types of SQL languages:

1 DDL Statement Database definition statement: Database, table, view, index, stored procedure, such as Create DROP ALTER

2 DML Statement Database manipulation language: Insert Delete update query data, insert Delete, update SELECT

3 DCL Statement Database Control Language: for example, to control the access rights of a user grant REMOVE

Action folder (Library):

Increase

Create Database db1 charset UTF8;

Check

Show CREATE Database db1; #查看刚新建的数据库

show databases;

Select Database (); #查看当前库

Change

ALTER DATABASE DB1 CharSet GBK;

By deleting

Drop database db1;

Database type:

INFORMATION_SCHEMA: Virtual library, do not occupy disk space, storage is the database startup parameters, such as user table information, column information, permission information, character information, etc.

Performance_schema:mysql 5.5 begins a new database that collects database server performance parameters, records various events that occur when processing query requests,

Locks and other phenomena

MySQL: Authorization library, access information for primary storage system users

Test:mysql Database System Auto-created test database

Action file (table)

Increase

Use DB1; # switch Libraries

Select Database (); # View your current folder

CREATE TABLE t1 (id int, name char);

CREATE TABLE t2 Select Id,name from T1 # Copy table

Check

Show Create table1;

Show tables;

Desc T1;

Change

ALTER TABLE T1 modify name char (6);

ALTER TABLE t1 change name name char (7);

By deleting

drop table T1;

Manipulate file contents (record)

Increase

Insert T1 (Id,name) VALUES (1, ' Egon1 '), (2, ' egon2 ');

Check

Select Id,name from Db1.t1;

SELECT * from Db1.t1\g; # when the \g record is more, the line break shows

Change

Update db1.t1 set name= ' SB ' where id=2;

By deleting

Delete from T1 where id=2;

Basic SQL statements

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.