SQL Small copy--sort of some handy tips for normal reference--follow-up

Source: Internet
Author: User

SQL statements

Statement Grammar
and/or SELECT column_name (s)
From table_name
WHERE condition
And|or condition
ALTER TABLE (add column) ALTER TABLE table_name
ADD column_name datatype
ALTER TABLE (drop column) ALTER TABLE table_name
DROP COLUMN column_name
As (alias for column) SELECT column_name as Column_alias
From table_name
As (alias for table) SELECT column_name
From table_name as Table_alias
Between SELECT column_name (s)
From table_name
WHERE column_name
Between Value1 and value2
CREATE DATABASE CREATE DATABASE database_name
CREATE INDEX CREATE INDEX index_name
On table_name (COLUMN_NAME)
CREATE TABLE CREATE TABLE table_name
(
Column_name1 Data_type,
Column_name2 Data_type,
.......
)
CREATE UNIQUE INDEX CREATE UNIQUE INDEX index_name
On table_name (COLUMN_NAME)
CREATE VIEW CREATE VIEW View_name as
SELECT column_name (s)
From table_name
WHERE condition
DELETE from DELETE from table_name
(Note: deletes the entire table!!)

Or

DELETE from table_name
WHERE condition

DROP DATABASE DROP DATABASE database_name
DROP INDEX DROP INDEX Table_name.index_name
DROP TABLE DROP TABLE table_name
GROUP by SELECT Column_name1,sum (column_name2)
From table_name
GROUP by column_name1
Having SELECT Column_name1,sum (column_name2)
From table_name
GROUP by column_name1
Having SUM (column_name2) condition value
Inch SELECT column_name (s)
From table_name
WHERE column_name
In (Value1,value2,..)
INSERT into INSERT into table_name
VALUES (value1, value2,....)

Or

INSERT into table_name
(column_name1, Column_name2,...)
VALUES (value1, value2,....)

Like SELECT column_name (s)
From table_name
WHERE column_name
Like pattern
ORDER by SELECT column_name (s)
From table_name
ORDER by column_name [asc| DESC]
SELECT SELECT column_name (s)
From table_name
SELECT * SELECT *
From table_name
SELECT DISTINCT SELECT DISTINCT column_name (s)
From table_name
SELECT into
(Used to create backup copies of tables)
SELECT *
Into New_table_name
From Original_table_name

Or

SELECT column_name (s)
Into New_table_name
From Original_table_name

TRUNCATE TABLE
(deletes only the data inside the table)
TRUNCATE TABLE table_name
UPDATE UPDATE table_name
SET Column_name=new_value
[, Column_name=new_value]
WHERE Column_name=some_value
WHERE SELECT column_name (s)
From table_name
WHERE condition

SQL Small copy--sort of some handy tips for normal reference--follow-up

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.