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; 





 

 

 

你可能感兴趣的:(数据结构,sql,mysql)