免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1592 | 回复: 0
打印 上一主题 下一主题

mysql中2个非常有用的查询 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-12 00:16 |只看该作者 |倒序浏览

                mysql中2个非常有用的查询
第一个:
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);
就直接把一个产品列表中数据全删除了
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/85566/showart_2024913.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP