"Go" database crud operations

Source: Internet
Author: User

Database CRUD Operations

Delete Table drop tables name

Second, modify the table

ALTER TABLE name adds column name data type (add indicates a column added)

ALTER TABLE name drop column name (column = Drop for drop means delete)

Third, delete the database

Drop database

Iv. crud Operations (create Add data read reading data update modify data delete remove data)

1. Add data (Create)

A:insert into + Nation values (' n002 ', ' hui ')--plus single quotes are converted to strings, English

B:insert into nation values (' n003 ', ') add only one column followed by empty to all additions that can be used

C:insert into Nation (code,) VALUES (' n004 ') add a column that can be used

D: Add insert into Nation (Code,name) values for multiple columns (' n004 ', ' Uighur ')

E: INSERT into table name dedicated to adding self-growth columns values (' p001 ', ' p006 ') self-growing column without tube, write second column directly

2. Deleting data (delete)

Delete from + table name--Delete all contents in table

Delete from + table name where ids=5 (delete this row)---where followed by a condition

3. Modify data (Uodate)

Update + table name set + column name = ' Set '---modify all the contents of this column

Update + table name set + column name = ' p006 ' where ids=6

Update + table name set + column name = ' p006 ', column name = ' p002 ' where ids=6-----separated by commas to modify multiple columns

Integer (int) is not required to add single quotes 0 (false) 1 (true)

4. Query data (10 kinds)

A1: Simple Query

SELECT * FROM table name--all data in the query table represents all columns

Select Code,name from table name--Query the specified column data

Select Code,name from table name--Check the data for the specified column

Select Code as ' Code ', name as ' from table ' name--Assign alias to column

A2: Conditional Query

SELECT * FROM table name where code= ' Check this line

SELECT * FROM table name where sex= ' true ' and nation= ' ' denotes side-by-side,--multi-conditional and relational

SELECT * FROM table name where sex= ' true ' or nation= '--multi-condition or relationship

A3: Range Query

SELECT * FROM table name where column name >40 and column name <50

SELECT * FROM table name where column name between 50--dedicated to range query

A4: Discrete Query

SELECT * FROM table name where column name in (', ' ', ')

SELECT * FROM table name where column name is not in (' ', ' ', ') inverse, not inside

A5: Fuzzy Query

SELECT * FROM table name where column name like '% BMW% '--check contains BMW's

SELECT * FROM table name where column name like ' BMW% '--look at the beginning of the BMW

SELECT * FROM table name where column name like '% BMW '--look at BMW end

SELECT * FROM table name where column name like ' BMW '-check equals BMW

SELECT * FROM table name where column name like '--e '--check the third one is E.

% represents any number of characters

-the underscore represents a character

A6: Sort Query

SELECT * FROM table name order BY column name--Default ascending sort

SELECT * FROM table name order by column name desc--descending order

SELECT * FROM table name order BY column name desc, column name asc--more than one conditional sort, preceded by a primary condition followed by a secondary condition

Desc Descending, ASC ascending, order by sort according to which column sort

A7: Paging Query

Select Top 5 * FROM table name--Query the first 5 data

Select Top 5 * from table name where code not in (select Top 5 code from car)

A8: Go to re-query (remove Duplicates)

Select DISTINCT column name from

A9: Group Query

Select brand from table name GROUP by Brand have Count (*) >2

Group BY having--indicates that count (*) >2--the number of each group based on a column grouping

A10: Aggregate function (statistical query)

Select COUNT (*) from table name--Query all data bars (per column)

Select COUNT (column name primary key) from table name--Query the number of all data bars in this column (execute fast)

Select SUM (column name) from table name--sum

Select AVG (column name) from table name--averaging

Select Max (column name) from table name--Seek maximum value

Select min (column name) from table name--Minimum value

"Go" database crud operations

Related Article

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.