SQL statement Base Management database, tables and data

Source: Internet
Author: User

Mysqlin the basicSQLStatement

MySQL mainly has three large objects, the first is a database, with a database, we can build a table in the database, because Mysql is a relational database, its data will be recorded in the form of the table, so the second is the tables, And then the third one is the data. Let's follow this relationship to learn about SQL statements in MySQL ~

SqlStatement Management database

1. See what databases are in MySQL

Statement : Show Databases

2. Create a database

Statement:

CREATE DATABASE Vmaxtam default character set UTF8;----Specify the defaults for creating a database

Then look at the following database:

3. Deleting a database

Statement: Drop database Vmaxtam;

4. Modify the Database

Modify the default character set for a database

Statement:mysql> ALTER DATABASE Vmaxtam default character set GBK collate gbk_chinese_ci;

SQL statement Management tables in the database

With the database, we can add a table to it ~

1. Add a table

Specify using that database, statement: Use Vmaxtam;

Then add a table with the header field name, the field type Plus,

Statement:

CREATE TABLE Student (

sname varchar (20),

Sage Int,

Gender varchar (2)

);

2. View the table

2.1 Viewing all tables in a database

Statement: Show tables;

 

2.2 Returns the information of a table in an SQL statement

Statement: Show create TABLE student;

2.3 A form returns header information

Statement: DESC student;

3. Modify the table

3.1 Add a field to the table, that is, add an attribute

Statement: ALTER TABLE student add column SID int;

      

3.2 Delete a field in a table (that is, delete a property)

Statement: ALTER TABLE student drop SID;

      

3.3 Modifying the data type of a field in a table

Statement: ALTER TABLE student modify Sage varchar (2);

      

3.4 Modifying the name of a field

Statement: ALTER TABLE student change gender sex varchar (2);

      

3.5 Modifying the name of a table

Statement: ALTER TABLE student rename Student_list;

      

Management of data in a table

1. Insert a record into the table (you need to specify which table to insert, and then enter the property values sequentially.) )

Statement: INSERT INTO student values (' Jax ',' n ', ' man ');

    

If you want values to be inserted into some property values, write this: INSERT INTO student (sname,sage) VALUES (' Jax ', 22);

    

2. Modify the data in the table

2.1 Uniform modification (sets the value of all record properties to the same)

Statement: Update student set sex= ' woman ';

    

2.2 Modify the property value of a record to be modified according to a specific condition

Statement: Update student set sex= ' man ' where sname= ' Jax ';

    

2.3 Modifying values for multiple fields at the same time

Statement: Update student set sname= ' Jax2 ', sage=23 where sname= ' Jax ';

      

3. Delete data

3.1 Delete a qualifying record in a table

Statement: Delete from student where sname= ' Jax2 ';

      

3.2 Clearing all records in a table

Statement: Delete from student;

      

SQL statement Base Management database, tables and data

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.