Home > Database > Mysql Tutorial > body text

sql复制表结构和数据的实现方法

WBOY
Release: 2016-06-07 18:01:03
Original
866 people have browsed it

将查询的结果放到一个新表中去,查询结果可以来源于一个表或多个表。

SQL SERVER中使用SELECT … INTO语句

按照使用场合可以分为以下几类:

1. 实现全表备份:如:SELECT * INOT t1 FROM titles

2. 备份表的一部分列(不写*而写出列的列表)或一部分行(加WHERE条件)

如: SELECT title_id,title,price INTO t2 FROM titles—部分列

SELECT * INTO t2 FROM titles WHREE price>10 –部分行

SELECT title_id,title,price INTO t2 FROM titles WHREE price>10 –部分行和部分列

3. 只复制表的结构:如:SELECT * INOT t1 FROM titles WHERE 1=2

4. 查询结果来源于多个表:如:

SELECT title_id,title,pub_name INTO t3

FROM titles t INNER JOIN publishers p

ON t.pub_id=p.pub_id

5.select * into 要复制到的数据库名.DBO.表名 from 原数据库名.DBO.表名
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