国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 郓城县| 莆田市| 三门峡市| 花莲市| 永胜县| 定日县| 湘潭市| 沙湾县| 通江县| 米易县| 祥云县| 西林县| 都江堰市| 若尔盖县| 宁城县| 固安县| 达孜县| 东乌珠穆沁旗| 疏勒县| 原阳县| 读书| 浦城县| 黎平县| 普陀区| 麻城市| 莫力| 阿尔山市| 佳木斯市| 长寿区| 南充市| 阜康市| 六枝特区| 江陵县| 祁门县| 大同市| 宝兴县| 始兴县| 即墨市| 吴堡县| 荃湾区| 荃湾区|