MySQL Basic article--Adding and deleting changes

Source: Internet
Author: User

Mysql-u User name-p*****//Enter database

Use database name;//Select Database

Show databases;//View Database

drop database name;//delete databases

Show create database data name;//View the statement that created the databases

Create DATABASE Database name CharSet utf8;//

Show tables;//View all tables

CREATE TABLE Table name (

ID Int (TEN) Auto_increment primary key,

Name varchar (5) NOT NULL

);

Constraints on the table:

1. Self-growth: aotu_increment

2. Non-empty: NOT NULL

3. Default value: Default ' XX (defaults) '

4. Unique constraint: Unique

5. Specify the character set: CharSet: Utf-8

6. Primary key: Primary key is unique and cannot be null

7. Foreign key:: ALTER table is used to represent a relationship between two tables

drop table name;//Delete tables

Delete form table name;//Remove data from the entire table truncate tablename, delete data from the entire table #delete empty table self-growth ID will continue to grow

Truncate empty table since the growth ID starting from 1, truncate faster than Delete, because truncate is directly from the disk to delete data, can not recover

Delete from blk where stu_name = ' condition ';//delete specified data

Change table:

1.alter table indicates rename new indication;//change indicates

2.alter table name modify such as: ID int (a) Not null;//modify table field

3.alter Table name change field name fields type varchar (+); #修改字段的数据类型

4.alter table name add field float not null after new field; #新增一个字段, where to put

5.alter table tablename drop field name;//delete field

6.update table name set field =**; If you do not specify a condition, the data for the entire table is modified

7.update table name set field =** where Condition field = ' * * * '; Modify the specified data

8.update table name set field =**, field where condition field = ' * * * '; Modify multiple fields

9.UPDATE table Name Set field = Field +100;//modify based on original value (int field)

Note: Modify and ALTER EXECUTE command completion (auto-commit), the UPDATE statement will not take effect until "commit" (requires manual submission)

desc indicates;//view table structure

Show tables;//View all tables

To add data to a table:

Insert into table name (specify added fields such as: Id,name)

VALUES (' 1 ', ' name ');

Simultaneous insertion of multiple strips available: (' 1 ', ' name '), (' 2 ', ' Name 2 '), (' 3 ', ' name 3 ');

Do not specify a field to add: "To write all dictionary values in full"

MySQL Basic article--Adding and deleting changes

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.