Mysql Learning Note 3: Table Basic Operations Introduction _mysql

Source: Internet
Author: User
To manipulate the table, you first need to select the database because the table exists in the database
Select Database
Mysql> Use school;
Database changed
After selecting the database, we can create the table in this database.
Create a table
Mysql> CREATE TABLE Student (
-> ID int,
-> name varchar (20),
-> Sex Boolean
->);
Query OK, 0 rows affected (0.11 sec)
Create table is for creating tables, followed by table names
The field name and type are written in parentheses, separated by commas, which indicate that varchar is a variable-length string
The 5 lines here can also be written in one line, so it's for clarity.
Show Table
Copy Code code as follows:

Mysql> Show tables;
+------------------+
| Tables_in_school |
+------------------+
| Student |
+------------------+
Row in Set (0.00 sec)

Show tables to display all tables in the current database
View Table Basic structure
Copy Code code as follows:

Mysql> describe student;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID | Int (11) | YES | | NULL | |
| name | varchar (20) | YES | | NULL | |
| sex | tinyint (1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
Rows in Set (0.00 sec)

field, data type, NULL, primary foreign key, default value, and extra information are shown here
Describe can also be abbreviated as DESC
In fact, most SQL statements can be abbreviated to four-character form
Note that the sex you just wrote is a Boolean type and will be automatically converted to the tinyint type
View Table Detail structure
Copy Code code as follows:

Mysql> Show CREATE TABLE Student\g
1. Row ***************************
Table:student
Create table:create Table ' student ' (
' id ' int (one) DEFAULT NULL,
' Name ' varchar DEFAULT NULL
) Engine=innodb DEFAULT charset=latin1
Row in Set (0.00 sec)

Show CREATE table shows the details when creating a table
After the end of the \g is to show more beautiful
Tips: \g endings are especially effective when displaying longer messages
Delete Table
mysql> drop table student;
Query OK, 0 rows affected (0.02 sec)
Deleting a table and deleting a database is similar to the operation
Using the drop command, you can use show tables to view the remaining tables when the deletion is complete

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.