国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

MySQL動(dòng)態(tài)添刪改列字段命令

2024-07-24 12:35:04
字體:
供稿:網(wǎng)友
  在mysql字段的操作通常是使用alert來進(jìn)行如修改,增加,刪除,改類型或修改自增ID等等,下面我整理了一些mysql字操作例子,一起來看看吧.
 
  MySQL如何動(dòng)態(tài)添刪改列字段呢,SQL如下:
 
  動(dòng)態(tài)增加列字段:ALERT TABLE table1 add transactor varchar(10) not Null;
 
  動(dòng)態(tài)刪除列字段:ALERT TABLE TableName drop column field_id;
 
  動(dòng)態(tài)修改列字段:ALERT TABLE table_name change old_field_name  new_field_name field_type;
 
  動(dòng)態(tài)修改表結(jié)構(gòu):ALERT TABLE table_name MODIFY field_name field_type
 
  創(chuàng)建表格后添加:alter table tablename add id int auto_increment primary key
 
  設(shè)置自增字段初始值:alter table tablename  auto_increment =x ;
 
  設(shè)置主鍵:alter table tablename add primary key(field_name);
 
  創(chuàng)建復(fù)合主鍵:
 
  create table tablename (  
  --phpfensi.com
    studentno int,  
    courseid int,  
    score int,  
    primary key (studentno,courseid) );
  設(shè)置復(fù)合主鍵:alter table tablename add primary key (列1,列2,列3);
 
  重命名表:alter table table_old_name rename table_new_name;
 
  改變字段的類型:alter table tableName modify field_name field_type;
 
  重命名字段:alter table tableName change old_field_name new_field_name new_field_type;
 
  刪除字段:alter table tableName drop column field_name;
 
  增加一個(gè)新字段:alter table tableName add new_field_name field_type;  
 
  新增一個(gè)字段,默認(rèn)值為0,非空:alter table tableName add new_field_name field_type not null default '0';
 
  新增一個(gè)字段,默認(rèn)值為0,非空,自增,主鍵:alter table tabelname add new_field_name field_type default 0 not null   auto_increment,add primary key (new_field_name);
 
  修改字段類型:alter table tablename change filed_name filed_name new_type;。
 
 

(編輯:武林網(wǎng))

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大关县| 余庆县| 成安县| 徐州市| 陆川县| 油尖旺区| 晋江市| 岳西县| 黑水县| 连南| 大宁县| 西丰县| 侯马市| 威信县| 句容市| 宜兰县| 汕尾市| 栖霞市| 晋中市| 昆明市| 陵水| 肇州县| 凤翔县| 准格尔旗| 改则县| 石楼县| 乌拉特前旗| 永年县| 确山县| 临夏县| 崇礼县| 铁岭市| 吴桥县| 彰化市| 盈江县| 禹州市| 光泽县| 皮山县| 衡东县| 沁水县| 栾川县|