A preliminary study of SQL statements

Source: Internet
Author: User

▲sql

Structured query Language, structured querying language. Almost all relational databases use SQL for query, management, and common operations.

In addition to the SQL standard, most SQL databases have their own private extensions.

▲ Common Statements

#查询MySQL版本

SELECT VERSION ();

#退出MySQL系统

Quit

#基本数学运算

SELECT 3+4;

#查询显示所有的数据库

SHOW DATABASES;

▲ Database Management Statements

#创建名为mydb的数据库

CREATE DATABASE MyDB;

#删除名为mydb的数据库

DROP DATABASE MyDB;

#选择使用名为mydb的数据库

Use MyDB;

#MySQL不支持对数据库重命名

▲ Data Sheet Management statement

The data in the data table is saved as a table. Each column is a property, and each row is a record.

#查询显示所有的数据表

SHOW TABLES;

#创建名为mytable数据表

CREATE TABLE MyTable

(

Column Name 1 data type,

Column Name 2 data type,

Column name 3 data type,

......

);

#查看名为mytable的数据表的表结构

DESCRIBE mytable;

DESC mytable;

#删除名为mytable的数据表

DROP TABLE mytable;

#将名为mytable的数据表重命名为mytable_new

ALTER TABLE mytable RENAME mytable_new;

#向名为mytable的数据表添加一列, column name link, data type varchar (50)

ALTER TABLE mytable ADD link varchar (50);

#删除名为mytable的数据表中的一列, column name link

ALTER TABLE mytable DROP COLUMN link;

#修改名为mytable的数据表中某一列的数据类型, column name link

ALTER TABLE mytable MODIFY link varchar (100);

#将名为mytable的数据表中的某一列重命名, link renamed to Link_new

ALTER TABLE mytable Change COLUMN link link_new varchar (100);

#向表中插入一行记录

INSERT into table name values (value 1, value 2,...);

INSERT into table name (column 1, column 2) VALUES (value 1, value 2);

Note: All strings need to be quoted in single quotation marks.

#从表中查询记录

SELECT * from table name;

SELECT column 1, column 2,... from table name;

#从表中查询记录, and merge delete duplicates

SELECT DISTINCT column name from table name;

#从表中查询记录 and sort by the specified column (desc is required in reverse order)

SELECT * FROM table name ORDER by column name;

SELECT * FROM table name ORDER by column name DESC;

#从表中条件查询

SELECT column name from table name WHERE column operator value;

Note: Where the operators are supported are =,<>,>,<,>=,<=,between,like

SELECT * FROM table name WHERE condition 1 operator Condition 2

Note: The supported operators have And,or

#从表中删除一行记录

DELETE * from table name;

DELETE from table name WHERE column operator value;

#更新表中的某一条记录

UPDATE table name SET column name = new value WHERE column = value;

Note: All strings need to be quoted in single quotation marks.

A preliminary study of 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.