"MySQL notes" data definition language DDL

Source: Internet
Author: User

1. Create basic table   creation table < table name > (< column name >< data type >[column-level integrity constraints]                                                         [,< Column name >< data type >[column-level integrity constraints]                                                         .........                                                         [,< Table-level integrity constraints;]);  Example:
  
 
  1. create table student(
  2. Sno char(5) not null unique,
  3. Sname char(20) unique,
  4. Ssex char(1),
  5. Sage int,
  6. Sdept char(15)
  7. );

2. Modify Basic Table Alert table < table name > [Add < New column name > < data type > [integrity constraint]]                                   [Drop < integrity constraint name;] [Modify < Column name >< data type >]; 1) Add: Used to add new columns and new columns related integrity constraints to the table, the new column increases successfully without any data
         Alert Table student add scome date;
2) Drop: Used to delete the specified integrity constraint
     Alert Table student drop unique (Sname);
3) Modify: Used to modify the original column definition, including modifying the column name and data type, the column data type modification may lose the original data     Alert Table student Modify Sage smallint;
        Note: SQL does not provide the ability to delete attribute columns, if you need to delete columns, you must indirectly through the SELECT statement, copy the contents of the required columns to another table, delete the original table, and then name the new table as the original table name3. Delete base table drop table < table name > 4, Build and delete index 5.1 create [unique] [cluster] Index < index name > on < Table name > (< column name > [< order][,< Column name >[< order] ...); Cases:              Create unique index studentindex on student (SNO);Note: 1) Unique: Indicates that each index value for this index is only one record for Chong 2)cluster: The index to be established when the table is clustered, that is, after a column is indexed, the data storage order on the hard disk is also adjusted to be stored in the order of the column, and the order of the indexes is consistent with the order of storage.
5.2 Delete Drop Index < index name >; example:              DROP index studentindex;
Links:http://blog.csdn.net/zdwzzu2006/article/details/2298777


From for notes (Wiz)

"MySQL notes" data definition language DDL

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.