Database Fundamentals 4 (MySQL Syntax---table)

Source: Internet
Author: User

5 Table Management

Select Database

5.1 View all tables

Mysql> Show tables;

+-----------------+

| TABLES_IN_DAY15 |

+-----------------+

| Student |

+-----------------+

1 row in Set (0.00 sec)

5.2 Creating a table

Mysql> CREATE TABLE Student (

-Sid int,

sname varchar (20),

Sage INT

);

Query OK, 0 rows affected (0.01 sec)

5.3 View table structure

mysql> desc Student;

+-------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| Sid | Int (11) |     YES | |       NULL | |

| sname | varchar (20) |     YES | |       NULL | |

| Sage | Int (11) |     YES | |       NULL | |

+-------+-------------+------+-----+---------+-------+

3 rows in Set (0.01 sec)

5.4 Deleting a table

mysql> drop table student;

Query OK, 0 rows affected (0.01 sec)

5.5 Modifying a table

1) Add field

Mysql> ALTER TABLE student add column Sgender varchar (2);

Query OK, 0 rows affected (0.03 sec)

records:0 duplicates:0 warnings:0

2) Delete field

mysql> ALTER TABLE student drop column sgender;

Query OK, 0 rows affected (0.03 sec)

records:0 duplicates:0 warnings:0

3) Modify the field type

mysql> ALTER TABLE student Modify column remark varchar (100);

Query OK, 0 rows affected (0.07 sec)

records:0 duplicates:0 warnings:0

4) Modify the field name

mysql> ALTER TABLE student change column sgender gender varchar (2);

Query OK, 0 rows affected (0.03 sec)

records:0 duplicates:0 warnings:0

5) Modify table name

mysql> ALTER TABLE student rename to teacher;

Query OK, 0 rows affected (0.01 sec)

Database Fundamentals 4 (MySQL Syntax---table)

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.