SQL语句实现,SQL Server 2000 及ACCESS复制旧表OldTable的结构,或结构及内容到新的表NewTable
两个都试过了,下面的代码在这两个数据库中(SQL Server 2000 及ACCESS)都是可以通过的。
--复制表结构为新的表
select * into NewTable from OldTable where 1=2
--复制表结构及内容到新的表
select * into newtable from oldtable
如果您只需要旧表的或以前表的某一些字段,或汇总后的内容合成一个字段的话,可以这样
--复制表结构内的某些字段为新的表
select title,type,price into NewTable from OldTable where 1=2
--复制表结构及内容到新的表,可以选择字段
select title,type,price into NewTable from OldTable
您也可以这样,先复制表结构(可以选一些字段为新的表),再插入内容
--复制表结构内的某些字段为新的表
select title y1,type y2,price into NewTable from OldTable where 1=2
--向新的表里添加数据
insert into NewTable(y1,y2,y3) select title,type,price from OldTable
insert into 可以加字段
insert into NewTable(new_column) select new_column from OldTable
insert into tab_new select * from tab_old;
当然,你需要先建立好tab_new结构,否则皮之不存,毛将焉附。