mysql下复制表和内容
将 production 数据库中的 mytbl 表快速复制为 mytbl_new,2个命令如下:
CREATE TABLE mytbl_new LIKE production.mytbl;
INSERT mytbl_new SELECT * FROM production.mytbl;
第一个命令是创建新的数据表 mytbl_new ,并复制 mytbl 的数据表结构。
第二个命令是讲数据表 mytbl 中的数据复制到新表 mytbl_new 。
这里的 production.mytbl 是指定要复制表的数据库名称为 production 。它是可选的。
如果没有 production. ,MySQL将会假设 mytbl 在当前操作的数据库。
mysql插入和修改某个字段内容
UPDATE的功能是更新表中的数据。这的语法和INSERT的第二种用法相似。必须提供表名以及SET表达式,在后面可以加WHERE以限制更新的记录范围。
UPDATE table_anem SET column_name1 = value1, column_name2 = value2, ...
WHERE ... ;
例子:
使用UPDATE更新多个字段的值 UPDATE users SET age = 24, name = 'Mike' WHERE id = 123;
mysql清空表内容的命令
用truncate table 表名 是可以让这个数据表重新计算的。
mysql改变某个字段属性命令
用alter table table_name change col_name new_col_name varchar(30) not null;
例子:
把client_level字段类型int型改为varchar类型并且把缺省为空改为不空
alter table client_table change client_level client_level varchar(30) not null
mysql中插入某个字段的命令
用alter table table_name add col_name int(5) not null;
例子:
插入dengji字段到 user_table 类型为int 缺省不为空
alter table user_table add dengji int(4) not null;
mysql中查找相同记录的命令
select * from client_table a where (a.client_name) in (select client_name from client_table group by client_name having count(*) > 1) ;
select * from 表名
where name in (select name from 表名 group by name having count(name) > 1)
mysql建立索引 alter table user_table add index username(username);
(索引名字)(字段名字)
mysql 修改表名 ALTER TABLE table_name RENAME TO new_table_name;
mysql中结果集的信息
ResultsetMetaData rsdata=resultset.getMetaData();
结果集中的各个方法:
getColumnCount():返回一个int值,指出结果集中的列数
getTableName(int column):返回一个字符串,指出参数中所代表列的表的名称
getColumnLabel(int column):返回一个String对象,该对象是column所指的列的显示标题
getColumnName(int column):返回的是该列在数据库中的名称.
getColumnType(int column):返回指定列的SQL数据类型.它的返回值是一个int值.在java.sql.Types类中有关于各种SQL数据类型的定义.
getColumnTypeName(int column):返回指定列的数据类型在数据源中的名称.它的返回值是一个String对象
isReadOnly(int column):返回一个boolean值,指出该列是否是只读的.
isWriteable(int column):返回一个boolean值,指出该列是否是可写的.
isNullable(int column):返回一个boolean值,指出该列是否允许存入一个NULL的值.
1138

被折叠的 条评论
为什么被折叠?



