mysql怎么复制语句 mysql如何复制一条数据( 二 )


".$r[$i]['cateid'].",
news_catid,
catid,
typeid,
areaid,
title,
style,
thumb,
keywords,
keywords,
posids,
url,
listorder,
status,
userid,
username,
inputtime,
updatetime,
searchid,
islink,
prefix
FROM
phpcms_content
WHERE
contentid
=
'".$r[$i-1]['aid']."')
大致为:insert
into
a
SELECT
id+1,
...(其它字段)
FROM
a
;
下面PHP具体程序:
$query
=
"SELECT
*
FROM
articleincategory
ORDER
BY
ArticleID
";
$result
=
$connector
-
query($query);$i
=
0;while($myrow
=
$connector
-
fetch_array($result)){$r[$i]['aid']
=
$myrow["ArticleID"];
$r[$i]['cateid']
=
$myrow["CategoryID"];$i++;}
for($i
=
0;
$i
count($r);
$i++){if($i
0){if(
$r[$i]['aid']
==
$r[$i-1]['aid']
){echo
'第
'.
$i.
'
条数据
'.
$r[$i]['aid']
.'
与前一条数据
'.
$r[$i-1]['aid']
.'
重复'.'/';
$sql
=
"
INSERT
INTO
phpcms_content
(SELECT
".$r[$i]['aid']."
+
520,
".$r[$i]['cateid'].",
news_catid,
catid,
typeid,
areaid,
title,
style,
thumb,
keywords,
keywords,
posids,
url,
listorder,
status,
userid,
username,
inputtime,
updatetime,
searchid,
islink,
prefix
FROM
phpcms_content
WHERE
contentid
=
'".$r[$i-1]['aid']."')
";
//$sql
=
"
INSERT
INTO
phpcms_c_news
(SELECT
".$r[$i]['aid']."
+
520,
template,
titleintact,
content,
groupids_view,
readpoint,
author,
copyfrom,
paginationtype,
maxcharperpage,
sub_title
FROM
phpcms_c_news
WHERE
contentid
=
'".$r[$i-1]['aid']."')
";
echo
$sql.'
/';
//$result
=
$connector
-
query($sql);
//INSERT
INTO
test
(SELECT
id
+
10,
name,
class,
score
FROM
test
WHERE
id
=
'1');}
else
if(
$r[$i]['aid']
!=
$r[$i-1]['aid']
){$sql
=
"
UPDATE
phpcms_content
SET
origin_cateid
=
'".$r[$i]['cateid']."'
WHERE
contentid
=
'".$r[$i]['aid']."'
";
echo
$sql.'
/';
//$result
=
$connector
-
query($sql);}}}如果不需要插入
mysql如何复制数据到同一张表?在利用数据库开发时mysql怎么复制语句,常常会将一些表之间mysql怎么复制语句的数据互相导入 。当然可以编写程序实现 , 但是,程序常常需要开发环境,不方便 。最方便是利用sql语言直接导入 。既方便而修改也简单 。以下就是导入mysql怎么复制语句的方法 。
1、 表结构相同的表,且在同一数据库(如,table1,table2)
Sql mysql怎么复制语句:
复制代码代码如下:
insert into table1 select*from table2 (完全复制)
insert into table1 selectdistinct*from table2(不复制重复纪录)
insert into table1 selecttop 5 *fromtable2 (前五条纪录)
2、不在同一数据库中(如 , db1 table1,db2 table2)
sql:
[code]
insert into db1.table1 select*from db2.table2 (完全复制)
insert into db1.table1 selectdistinct*from db2table2(不复制重复纪录)

推荐阅读