mysql 对表的操作

CREATE TABLE `table2222` (
  `id` int(11) NOT NULL,
  `name` char(30) NOT NULL,
  `age` int(11) NOT NULL,
  `info` varchar(255) DEFAULT NULL,
  FULLTEXT KEY `FullTxtIdx` (`info`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

1.修改表名

#alter table test_table1 RENAME TO table2222

2.修改主键的id字段类型 为bigint

#alter table table2222 MODIFY id BIGINT

3.修改字段名

#alter table table2222 CHANGE name  username char

4.添加字段

#alter TABLE table2222 add name VARCHAR(255) not NULL 默认插入
#alter TABLE table2222 add name VARCHAR(255) not NULL FIRST 插入第一列
#alter TABLE table2222 add name VARCHAR(255) not NULL AFTER address 在address列之后插入一列

5.删除列

#ALTER TABLE table2222 drop NAME 

6.修改字段的位置

#alter table table2222 MODIFY 字段1 数据类型 FIRST|AFTER 字段2

7.更改表的存储引擎

#alter table table2222 ENGINE=更改后的存储引擎名

8.删除表的外键约束

alter TABLE table2222 DROP FOREIGN key 外键约束名

9.删除没有被关联的表

drop table  t1

10.删除被关联的主表

	#1.先删除外键关联
	#2.再删除表

猜你喜欢

转载自blog.csdn.net/yinlell/article/details/85161652