MySQL (ii)

Source: Internet
Author: User

Table operation of the data 1. Create a table

Syntax: CREATE TABLE table_name (column_name column_type);

CREATE TABLE student,    ID int not NULL auto_increment,    name CHAR (+) NOT NULL,--age    INT not NU LL,    register_data DATE,    PRIMARY KEY (ID)    );

Auto_increment said: increased by 1. When the write content is empty, the default is to populate the table with a drop-down. Primary key: Represents a constraint (cannot be duplicated and cannot be empty); Accelerate find NOT null: not empty

2. View the table
Show tables;      --See what tables are DESC student;     --View Student table information show create table student;    -View the information created by table student

3. Delete a table
#drop Table name drop table student;
4. Modify the table

Method:

Add Column: ALTER TABLE table name add column name type Delete column: ALTER TABLE table name drop Column name Modify column:        ALTER TABLE table name modify column name type;  --type ALTER TABLE name change original column name        new column name type;--column name, type   add primary key:        ALTER TABLE table name add primary key (column name); Delete PRIMARY key:        alter TABL e table Name drop primary key;        ALTER TABLE name  modify  column name int, drop primary key;   Add foreign key: ALTER TABLE from TABLE ADD constraint foreign key name (shape: fk_ from Table _ Main Table) foreign key from table (foreign key field) references Main Table (primary key field); Delete foreign key: ALTER TABLE name drop for Eign key FOREIGN Key name   modifies default value: ALTER TABLE TESTALTER_TBL alter I SET default 1000; Delete defaults: ALTER TABLE TESTALTER_TBL alter I DROP D Efault;
1. Add alter TABLE student add sex CHAR (+);    #--> add a column 2. Delete alter TABLE student drop sex;     #--> Delete a column 3. Modify the table name alter tables student RENAME to students;   #--> Rename 4. Modify the column name alter TABLE students change regisiter_date register_date date, #change field name, type can be changed, modify can only change type

  

MySQL (ii)

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.