SQL Server复制表结构和数据

1、复制表结构,当新表名称未经在,数据库会创建一个新表
select * into 新表名称 from 旧表名称 where 1=2;

2、复制表数据,当新表名称已经在

insert into 新表 select * from  旧表 ;

 

INSERT INTO新表(字段1,字段2,.......)SELECT字段1,字段2,...... FROM 旧表

 

3、清空表数据

delete from tablename

 4、表中有外键时,要用级联方式删所有关联的数据

truncate table tablename cascade;

 5、设置序列起始值为1

alter sequence tablename_id_seq start 1;

 

临时表

select top(20)* into #AA from orc630    --查询Table中的数据,并将数据加入到临时表中
select * from #AA where manfac in('190658017','168026001')--通过查询临时表中指定的数据
select * from #AA --查询整个临时表的数据
posted @ 2023-06-27 10:35  microsoft-zhcn  阅读(455)  评论(0)    收藏  举报