sql重命名表名和列名

mysql 为例: 

 

 

显示表结构

describe jin;

 

 

将表jin重命名为chun 

 

 

 

rename table jin to chun; 

 

 

 

或者 

 

 

 

alter table jin rename to chun; 

 

 

 

 

 

重命名列 --要列出列的类型, column可有可无

 

alter table jin change column  name pass varchar(50);

 

 

 

检索表 

 

 

 

show tables like 'jin%' 

 

 

 

 

 

同一数据库里的table1表的内容导入到table2中? 

 

 

 

insert into table2 select * from table1; 

 

 

 

 

 

 

 

##mysql重命名表,建立外键,增、删、改列名实例 

 

##增加到某个字段之后 

alter table tb_nippon_mms_info add province varchar(50) default null after retCode; 

alter table tb_nippon_mms_info add city varchar(50) default null after province; 

 

##增加到某个字段之前 

alter table tb_nippon_mms_info add province varchar(50) default null before retCode; 

alter table tb_nippon_mms_info add city varchar(50) default null before province; 

 

 

##删除名字为states的列 

alter table tb_nine_integral_mo_info drop column states ; 

 

##改变手机号码字段为约束键 

alter table business.tb_nine_ticket_popedom change phone phone varchar(50) not null unique; 

 

##改变列名flag为states 

alter table tb_nine change flag states tinyint(1); 

 

 

–重命名表 

rename table t_softwareport to software_port; 

 

–建立外键 

alter table software_port add constraint fk_software_port_softwareprocessid foreign key (softwareprocessid) 

references software_process (id) on delete restrict on update restrict; 

 

来自:http://jinchun1223.iteye.com/blog/736653

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值