Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45814
  • 博文数量: 11
  • 博客积分: 383
  • 博客等级: 一等列兵
  • 技术积分: 133
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-17 19:54
文章分类

全部博文(11)

文章存档

2012年(3)

2011年(8)

我的朋友

分类: Mysql/postgreSQL

2012-09-01 10:59:55

现在要经常接触MySQL数据库了,各种小命令乱七八糟的常常忘记,在这里做个备忘录,以后会经常来更新一下。b
背景:数据库名dbname,表名table1,table2。
1、向原有表中添加一列,列名为id,类型为int(10),主键
alter table table1 add id int(10) primary key;
2、删除添加的列名为id的列
alter table table1 drop id;
2、向原有表中添加一列,列名位id,类型为int(10),自增长,(自增长列必须在主键序列中)
alter table table1 add id int(10) primary key auto_increment;
3、自增长序列序号从1开始
alter table table1 auto_increment=1;
4、如果原有表中已经存在主键(假设为col1,col2),还想添加一列自增长的列id,类型为int(10),自增长序列序号从1开始,首先需要删除原有的主键,并将col1,col2,id联合作为主键
alter table table1 drop primary key;
alter table table1 add id int(10) primary key auto_increment;
alter table table1 auto_increment=1;
alter table table1 drop primary key, add primary key(col1, col2, id);
5、将第一列col1的内容复制到第二列col2
update table table1 col2 = col1
6、为表table1中的列col1,类型为varchar(10)建立索引index_col1
create index index_col1 on table1(col1(varchar(10)));
阅读(785) | 评论(0) | 转发(0) |
0

上一篇:让程序汇报工作进度

下一篇:没有了

给主人留下些什么吧!~~