网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 网络学院 >> 数据库教程 >> MySql >> 文章正文
  mysql中2个非常有用的查询            【字体:
mysql中2个非常有用的查询
作者:佚名    文章来源:不详    点击数:    更新时间:2007-6-30    

不多。但是自己写的
第一个:

INSERT ... SELECT Syntax

用处:数据转换(特别是数据量大的时候),我测试过。转换100万数据也只是用秒计划就OK了。
INSERT [LOW_PRIORITY] [IGNORE] [INTO] tbl_name [(column list)]
    SELECT ...
With INSERT ... SELECT, you can quickly insert many rows into a table from one or many tables.

For example:

INSERT INTO tblTemp2 (fldID)
    SELECT tblTemp1.fldOrder_ID FROM tblTemp1
    WHERE tblTemp1.fldOrder_ID > 100;
The following conditions hold for an INSERT ... SELECT statement:

Prior to MySQL 4.0.1, INSERT ... SELECT implicitly operates in IGNORE mode. As of MySQL 4.0.1, specify IGNORE explicitly to ignore records that would cause duplicate-key violations.
Do not use DELAYED with INSERT ... SELECT.
Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
AUTO_INCREMENT columns work as usual.
To ensure that the binary log can be used to re-create the original tables, MySQL will not allow concurrent inserts during INSERT ... SELECT.
You can use REPLACE instead of INSERT to overwrite old rows. REPLACE is the counterpart to INSERT IGNORE in the treatment of new rows that contain unique key values that duplicate old rows: The new rows are used to replace the old rows rather than being discarded.


2.in的用法。这个好处很多。特别是删除数据的时候可以不用whil循环就行了
比如语句:
$SQL = sprintf("DELETE FROM ".PRODUCTOPTION_TABLE." WHERE (productOptionID IN ('%s'))",join("','", $_POST['fieldsID']));
        $DB->query($SQL);

就直接把一个产品列表中数据全删除了
还有查询的时候同样很有用。就不写了。随便乱写的
站内文章搜索 高级搜索
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • 看紧你的3306端口,一次通过…

  • 从MySQL导出XLS数据库工具(跨…

  • 禁止Mysql默认端口访问Inter…

  • MYSQL用户root密码为弱口令的…

  • MySQL从后门进企业市场

  • MySQL数据导入导出方法与工具…

  • MySQL数据库和备份与恢复

  • 使用MySql ODBC进行MYsql和M…

  • 怎样使MySQL更安全 才能有效…

  • 导入大量MYSQL数据的方法

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    网络学院©2007 www.23book.net
    为您提供web编程,vb编程,vc编程,服务器架设管理,数据库设计等方面的知识 站长:David