---
title: "Sybase:select ...into/insert...select"
author: "Ashton"
date: "2007-06-12T23:39:54Z"
tags: []
slug: "sybase-select-into-insert-select"
draft: false
lastmod: "2007-06-12T23:39:54Z"
id: 89561
url: "https://ashton.iteye.com/blog/89561"
---

在使用数据库的时候，有时我们需要把一个表中的数据经过筛选插入另外一个表中。Sybase提供一种特殊的方式来实现这一功能，例如  
insert into boy  
select id,name  
from person  
where type='boy'  
通过insert .... select ...语句，select的结果会被直接插入表boy中，并且每个插入操作都会被记录到事务日志之中

Sybase还提供了一种"select ... into"语句实现类似功能  
例如，  
select  id,name  
from person  
where type='boy'  
into boy  
这时一个拥有字段id和name的表boy会被自动创建，select的结果会被直接插入新建的表中，但操作并不会被记录到事务日志，并且select..into只有在事务日志trun off 之后方可使用