SQL Basic Syntax:

Source: Internet
Author: User

1, create database db_name; --Create a database

2, drop database db_name; --Delete Database

3, show create database db_name\g; --View the CREATE DATABASE statement, \g the vertical vertical lines display.

4, show database; --Displays the system's database.

5. Select database ();--View the currently connected databases.

6, Select version (); --View the current database version.

7, Select User (); --View the database of the logged-on user.

8. Use db_name--connect database

9, Grant privilege_x,privilege_x on db_name.db_table to ' u_name ' @ ' u_host_ip ' identified by ' password '; --Create user authorization for user

10. GRANT

SELECT,

INSERT,

UPDATE,

DELETE,

CREATE,

DROP,

REFERENCES,

INDEX,

Alter

CREATE Temporary TABLES,

LOCK TABLES,

EXECUTE,

CREATE VIEW,

SHOW VIEW,

CREATE ROUTINE,

ALTER ROUTINE,

EVENT,

TRIGGER on ' Test '. * to ' king ' @ ' 1.1.1.1 '-all rights of the user all privilege

11, revoke privilege_x on db_name.t_name from ' user ' @ ' u_host_ip '; --Recover user rights

12. Show grants for ' Test ' @ ' 1.1.1.1 '--View specific user's permissions

13. CREATE table < table name > (< Field name 1>< type 1>,..........;< field name n>< type n>); hint Where: CREATE TABLE is a keyword, cannot be changed, But the case can vary.

Eg:create table test (id int) NOT NULL Auto_increment,name varchar (TEN) NOT null default ' ', card int (k) unique,primary EY (ID), key index_name (name)) Engine=innodb default Charset=utf8;

14, Desc t_name; --View Table structure type: field type, null: null, key: Primary key or index, default: defaults to. Extra: Others.

15, show create TABLE t_name\g; --View the Build table statement

16. drop table [IF EXISTS] < table name >; --Delete Table

17. Alter table T_name Drop primary key;--delete primary key index

18. ALTER TABLE T_NAME change ID ID int primary key auto_increment; Add primary Key

19, ALTER TABLE t_name rename new_name; --Modify Table name

20. ALTER TABLE < table name > Modify < Field name > < data type >; --Modify data field data type;

21. ALTER TABLE < table name > change < old field name > < new field name > < new field type >; --Modify data field names

22. ALTER TABLE < table name > Add < Field name > < field type > [constraint] [first | After existing field name]; --Add Field

23. ALTER TABLE < table name > drop < Field name >; --delete field;

24. ALTER TABLE < table name > Engine=inndob; --Change the table's storage engine;

25. ALTER TABLE < table name >drop foreign key < foreign key Name >--Deletes the foreign KEY constraint for the table.

26. Insert INTO T_name SET < field 1>= value 1,< field 2>= value 2,< field n>= value 2; --Inserts a single row of data.

27. Insert INTO T_name [(Field 1, Field 2, field N)] values (value 1, value 2, Value N), (value 1n, value 2n, value nn)--insert multiple rows of data.

28. Insert Into T_name (field 1, Field 2, Field N) Select field A, field B, field C from T_name [where condition]; Inserting query results into a table, which belongs to the fast data creation

29.

SQL Basic Syntax:

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.