1凳干、創(chuàng)建表格時添加: create table tablename(id int auto_increment primary key,...)?
2养匈、創(chuàng)建表格后添加: alter table tablename add id int auto_increment primary key
3垃帅、設置主鍵:alter table tablename add primary key(field_name);
4腻暮、重命名表: alter table table_old_name rename table_new_name;
5、改變字段的類型:alter table tableName modify field_name field_type;
6捕犬、重命名字段:alter table tableName change old_field_name new_field_name new_field_type;
7矾瑰、刪除字段:alter table tableName drop column field_name;
8砖茸、增加一個新字段:alter table tableName add new_field_name field_type; ??
????????????????????????????????? alter table tableName add new_field_name field_type not null default '0';
9、新增一個字段殴穴,默認值為0凉夯,非空,自動增長采幌,主鍵:alter table tabelname add new_field_name field_type default 0 not null?? auto_increment ,add primary key (new_field_name);
創(chuàng)建一個表
create table pre_common_usernotes (id int(8) not null primary key auto_increment, user_id char(20) not null, order_id char(20) not null, pub_id char(20) not null, ad_name char(20) , ad_id int(8), device char(20) , system_name char(20), channel int(8), price double(16,2), point int(8), ts int(10) not null default'0', sign char(30));
創(chuàng)建數(shù)據(jù)庫并設置數(shù)據(jù)庫默認字段編碼格式
create database database_name default charset utf8 collate utf8_unicode_ci;
設置auto_increment字段的最小值
ALETER TABLE table_name AUTO_INCREMENT=100000