Mysql = = file (table)

Source: Internet
Author: User

Table Description:

A table is equivalent to a file, and a record in a table is equivalent to a row of files, and a record in a table has a corresponding title, called a field of a table, at different points.

For example: Id,name, age is called a field, and the rest, a line of content is called a record.

1. Create a table

Syntax: CREATE TABLE table name (field name 1 type [(width) constraint], field name 2 Type [(width) constraint]);
Example:
CREATE TABLE T1 (ID int,name char (12));
CREATE TABLE T1 (ID int,name char) engine =innodb default CharSet UTF8;
Note: 1. Field names cannot be the same in a single table. 2. Width and constraints are optional, that is, 3. Field names and types are required.

2. View the table

Syntax: 1.show tables;2.show CREATE table T1; View table structure: 1.describe  t1;  2.desc  T1;

3. Modify the table

Syntax: 1. ALTER TABLE T1 modify name char (n);   #修改表中字段的宽度2. ALTER TABLE course charset = UTF8;        #修改表中的类型3. ALTER TABLE T1 modify name char (n) character set UTF8; #修改表中的类型4. ALTER TABLE t1 rename T2;         #重命名表的名字5. ALTER TABLE T1 add age int;   #添加表中的字段6. ALTER TABLE T1 drop age;      #删除表中的字段7. ALTER TABLE t1 modify ID int not  null primary key auto_increment;  #修改为主键和自动增长8. ALTER TABLE t1 modify ID int not  null;   #删除自增约束9. ALTER TABLE T1 drop PRIMARY key;   #删除主键

4. Copying a table

Copy table structure + record (key will not be copied: primary key, foreign key and Index) syntax: 1. CREATE TABLE NEW_T1 select * from T1; Copy table structure only: 1.select * from T1 where 1=2;  #条件为假, no records are found, so the table's records are not copied 2.create table New_t2 select * from T1 where 1=2;  #只复制表的结构

5. Delete a table

Syntax: Drop  table  name; For example: drop table  t1;

  

Mysql = = file (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.