Discuz SQL MySQL new field add field Delete field Modify Field

Source: Internet
Author: User

MySQL
// Add a field
Alter table cdb_forumlinks add type smallint default 1;

Alter table cdb_forumlinks add views int default 0;

// Delete a field
Alter table cdb_forumlinks drop type;
Alter table cdb_forumlinks drop views;

// Modify the field
Alter table student change physics physisc char (10) Not NULL;
Char (10) Not null is the create_definition of your physisc field.

----------------------------------------
More...
// Add a field and set the primary key
Alter table tabelname add new_field_id int (5) unsigned default 0 not null auto_increment, add primary key (new_field_id );

// Index with the primary keyword
Alter table tablename add primary key (ID );

// Add an index
Alter table tablename change depno int (5) not null;
Alter table tablename add Index name (field name 1 [, field name 2…]);
Alter table tablename add index emp_name (name );

// Add an index with unique conditions
Alter table tablename add unique emp_name2 (cardNumber );

// Delete an index
Alter table tablename drop index emp_name;

// Add a field:
Alter table table_name add field_name field_type;

// Delete a field
Alter table table_name drop field_name;

// Rename a column
Alter table table_name change field_name1 field_name2 integer;

// Adjust the field order
Alter table 'users' change 'user _ password' varchar (20) not null after user_name;

// Change the column type
Alter table table_name change field_name bigint not null;
Alter table Infos change list tinyint not null default '0 ';

// Modify the original field name and type:
Alter table table_name change old_field_name new_field_name field_type;

// Rename the table
Alter table table_name rename new_table_name;

// Cascade update and delete (red, Case Insensitive)
Drop table if exists 'mail _ model'; Create Table mail_model (ID varchar (50) primary key not null, mail_filename varchar (200), content varchar (2000 )) engine = InnoDB default charset = GBK;

Drop table if exists 'mail _ model_extend '; Create Table mail_model_extend (ID int (6) auto_increment not null primary key, RID varchar (50) not null, content varchar (2000 ), index (RID), foreign key (RID) References mail_model (ID) on Delete cascade on update cascade) engine = InnoDB default charset = GBK;

 

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.