1.复制表结构:只能复制表的字段,不能复制主键、索引等
select top 0 * into 新表名 from 原表名
2.复制整个数据库结构及数据:
create datebase Test --创建目标数据库
exec P_CopyDB @Source_DB='aspnet',@Des_DB='test' --把源数据库整个复制到目标数据库
㈡ sql复制一条记录,除了主键
假设你的表名为A,主键为ID,要复制ID为1的记录,新纪录ID为999,要复制的记录有多少个字段都不用关心
select*into#tmpfromAwhereID=1
update#tmpsetID=999
insertintoAselect*from#tmp