对于表的部分或全部字段的复制,Sybase数据库提供了两种方式:select into和insert into。
select into:
语法:select value1, value2, value3 ...into table2 from table1.
注意:
①被插入的表table2必须是不存在的,在执行语句的时候创建table2表。如果已经存在,执行时会报错。
②插入的value1,value2,value3等 into #temp_table_two from #temp_table_one (如果只插入常量不命名,则会报错,报错信息如下所示)
插入常量时报错:
------------------------ Execute ------------------------
SELECT INTO failed because column 4 in table '#temp_table_two00005230001896877' has a null column name. Null column names are not allowed.
----------------- Done ( 1 errors ) ------------------
insert into:
语法:Insert into Table2(value1,value2,...) select value1,value2,... from Table1
注意:
①table2表必须已经存在。
②因为table2表已经存在,所以可以向其中插入常量。
例子:
①insert into tempdb..testtable4(id, name,age) select id, name, age from student
②insert into tempdb..testtable4 select * from student
③insert into tempdb..testtable4 select id, name, age from student
④insert into tempdb.. testtable4(id, name, age) select id, name, 27 from student (插入常量)