Home > Database > Mysql Tutorial > sql 表内容复制 INSERT INTO Select语法

sql 表内容复制 INSERT INTO Select语法

WBOY
Release: 2016-06-07 17:48:02
Original
1210 people have browsed it

sql 表内容复制 insert into select语法

insert into 新表(字段1,字段2,.......) select 字段1,字段2,...... from 旧表

_connect("localhost","root","123456");
mysql_select_db("db_test");
mysql_query("set names 'utf8'");
$query = mysql_query("insert into test2(id,title,date) select id,title,date from test1");
if($query){
        echo "ok";exit;
}

mssql 用法

--2.创建测试数据
    insert into table1 values('赵','asds','90')
    insert into table1 values('钱','asds','100')
    insert into table1 values('孙','asds','80')
    insert into table1 values('李','asds',null)
    go

    --3.select into from语句创建表table2并复制数据
    select a,c into table2 from table1
    go

    --4.显示更新后的结果
    select * from table2
    go
    --5.删除测试表

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template