mysql alter 语句用法,添加、修改、删除字段等
http://www.blogjava.net/Alpha/archive/2007/07/23/131912.html
//主键549830479
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列549830479
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
例2:alter table msglogabstract add subcaption int(255) default 0;
//删除列549830479
alter table t2 drop column c;
//重命名列549830479
alter table t1 change a b integer;
//改变列的类型549830479
alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default '0';
//重命名表549830479
alter table t1 rename t2;
加索引549830479
mysql> alter table tablename change depno depno int(5) not null;
mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);
mysql> alter table tablename add index emp_name (name);
加主关键字的索引549830479
mysql> alter table tablename add primary key(id);
加唯一限制条件的索引549830479
mysql> alter table tablename add unique emp_name2(cardnumber);
删除某个索引549830479
mysql>alter table tablename drop index emp_name;
修改表:549830479
增加字段:549830479
mysql> ALTER TABLE table_name ADD field_name field_type;
修改原字段名称及类型:549830479
mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
删除字段:549830479
mysql> ALTER TABLE table_name DROP field_name;
相关文档:
高性能MySql学习笔记
1.针对应用建立自己的索引
URL查找例子
select * from tUrl where url='http://www.163.com';
以url(字符串)作行为索引会使得作为索引结构的B-Tree变大,可以移除url列上的索引,并添加一个url_crc索引列,
先建立表:
create tables tUrl(
......
我的程序是用ADO来连接Mysq数据库的,这是原先写好用在MSSQL上的,改了下连接字符串,所以也就没有用MySql C++ API来重新写了。刚开始使用MySql,遇到的问题总是特别的多,现在又遇到一个主要sql字符串中有中文就报错的问题,没有中文一切正常,整整弄了一个上午,在网上也找了很多资料,发 ......
1,Mysql插入二进制大对象出现异常,插入二进制出现异常,怎么解决com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
解决办法:url=url=+"?useUnicode=true& ......
下面先来看看例子:
table
id name
1 a
2 b
3 c
4 c
5 b
库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。
比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录 ......
基础部分
一、MySQL 获得当前日期时间 函数
1.1 获得当前日期+时间(date + time)函数:now()
mysql> select now();
+---------------------+
| now() |
+----------------- ......