松软科技课堂:SQL-SELECT-INTO语句

sql select into 语句可用于创建表的备份复件。

select into 语句

select into 语句从一个表中选取数据,然后把数据插入另一个表中。

select into 语句常用于创建表的备份复件或者用于对记录进行存档。

sql select into 语法

您可以把所有的列插入新表:

	select *
into new_table_name [in externaldatabase] 
from old_tablename

或者只把希望的列插入新表:

	select column_name(s)
into new_table_name [in externaldatabase] 
from old_tablename

sql select into 实例 – 制作备份复件

下面的例子会制作 “persons” 表的备份复件:

	select *
into persons_backup
from persons

in 子句可用于向另一个数据库中拷贝表:

	select *
into persons in 'backup.mdb'
from persons

如果我们希望拷贝某些域,可以在 select 语句后列出这些域:

	select lastname,firstname
into persons_backup
from persons

sql select into 实例 – 带有 where 子句

我们也可以添加 where 子句。

下面的例子通过从 “persons” 表中提取居住在 “beijing” 的人的信息,创建了一个带有两个列的名为 “persons_backup” 的表:

	select lastname,firstname
into persons_backup
from persons
where city='beijing'

sql select into 实例 – 被连接的表

从一个以上的表中选取数据也是可以做到的。

下面的例子会创建一个名为 “persons_order_backup” 的新表,其中包含了从 persons 和 orders 两个表中取得的信息:

	select persons.lastname,orders.orderno
into persons_order_backup
from persons
inner join orders
on persons.id_p=orders.id_p
(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐