mysql 修改 添加 刪除 表字段


mysql 修改 添加 刪除 表字段
添加表的字段 alter table 表名 add 字段名 字段的類型

  例子:        alter table table1 add transactor varchar(10) not Null;

                  alter table   table1 add id int unsigned not Null auto_increment primary key

                  在mysql數據庫中怎樣在指定的一個字段后面添加一個字段:

                  alter table newexample add address varchar(110) after stu_id;

修改表的字段類型 ALTER TABLE 表名 MODIFY COLUMN 字段名 字段類型定義;

   例子:                  ALTER TABLE chatter_users MODIFY COLUMN ip VARCHAR(50);

修改表的字段名 alter table 表名 change 原字段名 新字段名 字段的類型

 例子: alter table student change physics physisc char(10) not null

刪除表的字段 alter table 表名 drop column 字段名

 例子:         alter table `user_movement_log` drop column Gatewayid

調整表的順序: ALTER TABLE user_movement_log CHANGE GatewayId GatewayId int not null default 0 AFTER RegionID

表的重命名 alter table 原表名 rename 現表名;

 例子:      alter table t1 rename t2;

刪除表的數據 delete from 表名 where (條件) id 不是從1開始 ,truncate table 表名 id是從1 開始的

創建表的例子

CREATE TABLE hlh_message (

   id int(11) NOT NULL AUTO_INCREMENT COMMENT '健康表id',

    title varchar(40) NOT NULL COMMENT '健康標題',

    hlh_url text DEFAULT NULL COMMENT '圖片地址',

    bewrite VARCHAR(350) NOT NULL COMMENT '描述',

    content VARCHAR(350) NOT NULL COMMENT '內容',

    type tinyint(1) NOT NULL DEFAULT '0' COMMENT '健康知識 0 健康咨詢 1',

    create_time date DEFAULT NULL COMMENT '發布消息的時間',

    PRIMARY KEY (id)

)ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='健康表'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM