A few simple SQL statements

Source: Internet
Author: User

Get started with simple SQL

First, Introduction

1, a database contains one or more tables, and the table contains records with data (rows)

2, SQL is not case sensitive, the semicolon of the statement to see the specific situation

Two, grammar

1, Data manipulation language: DML

A) SELECT: Get data from the database

b) Update: Updating data in a database table

c) Delete: Delete data from the database

d) INSERT into: Insert data into the data table

2, data definition language: DDL

A) CREATE database: Creating new databases

b) ALTER database: Modify Databases

c) CREATE table: Creating a new data table

d) ALTER table: Modify data table

e) DROP table: Delete data table

f) CREATE INDEX: Create indexes

g) DROP INDEX: Delete index

Third, SELECT

1, SELECT column name from table name

2, SELECT * from table name

Four, DISTINCT

1, select the data that is unique in the column

2, SELECT DISTINCT column name from table name

Five, where

1, conditional selection

2, SELECT column name from table name WHERE column name operator value

a) = (equals) <> (not equal to) > (greater than) < (less than) >= <= between (in a range) like (search for a pattern)

3, use of quotation marks, values for text need to use quotation marks, numeric values, no quotes required

VI, and and OR

1, concatenate multiple conditions in the WHERE statement

Seven, ORDER by

1, sorts the result set according to the specified column (default ascending), Desc is descending, ASC is ascending

2, SELECT column name from table name ORDER by column name (DESC OR ASC)

Eight, INSERT into

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

2, INSERT into table name (column 1, column 2,...) Values (value 1, value 2,....)

Nine, UPDATE

1, UPDATE table name set column name = new value WHERE Column name = specified value

2, set multiple columns, separated by commas

Ten, DELETE

1, DELETE * FROM table name

2, DELETE from table name WHERE column NAME = specified value,

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.