Create a complete table in the MySQL database, and create a mysql database

Source: Internet
Author: User

Create a complete table in the MySQL database, and create a mysql database

1. After successful login, first enter a database (not a database server)

Use t1; // t1 is the database name

:

2. Create a database table in this database

2.1 first create a table structure (which can be understood as the column name of the table, that is, the field name). In actual production, the table structure needs to be carefully designed.

The common syntax format is:

1 CREATE TABLE table_name (column_name column_type);

Example:

1 create table tb3(2    id smallint unsigned auto_increment primary key,3    username varchar(20) not null4    );

2.2 view the created table structure

Syntax format:

1 show columns from [Table name];

Example: show colums from Fig;

The table structure in Table t3 contains two fields: id and username;

The values of both fields cannot be blank, and the id field is the primary key.

3. insert and search records

The table records in the Database correspond to the rows in the table.

3.1 insert record

Syntax format of insert record:

Inset {table name} (filed1, field2,...) values (value1, value2 ,....);

Example:

1 insert tb3 (id,username) values (4,'jona');

 

3.2 query records

Syntax format:

1 select {filed1, filed2,...} from {table name };

Example:

Select id, username from Fig;

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.