sql server中如何把一个表结构复制到另一个新表中..

ahweb236 2007-12-11 04:18:22
sql server中如何把一个表结构复制到另一个新表中..
...全文
717 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxmcxm 2007-12-11
  • 打赏
  • 举报
回复
在要插入的表前加上
set identity_insert 表名 on
就可插入id列,插入完成后

set identity_insert 表名 off
即可恢复自增列
winstonbonaparte 2007-12-11
  • 打赏
  • 举报
回复

select ID = identity(int,1,1),* into #B from ZhG
--如果表ZhG有标识列,就不能用*号,要不然会报
服务器: 消息 8108,级别 16,状态 1,行 1
无法使用 SELECT INTO 语句向表 '#B' 中添加标识列,该表中已有继承了标识属性的列 'ID'。
caoaijing 2007-12-11
  • 打赏
  • 举报
回复
如果你用2000库,则用DTS的中导数据的功能,但是只进行创建数据库结库就可以了
caoaijing 2007-12-11
  • 打赏
  • 举报
回复
可用DTS中功能
xiangyu120 2007-12-11
  • 打赏
  • 举报
回复
select ID=(select count(ID)+1 from tablea where ID<a.ID),* into newtable from tablea a
wzy_love_sly 2007-12-11
  • 打赏
  • 举报
回复
select id=identity(int,1,1),* into newtable from oldtable

有标试列就别用星了,挨个写就行了
woshiccye_msdn 2007-12-11
  • 打赏
  • 举报
回复
// 将A表中的结构复制到B表中,但数据不复制
select * into B from A where 1=0

// 将A表中的结构和数据全都复制到B表中
select * into B from A
ahweb236 2007-12-11
  • 打赏
  • 举报
回复
那旧表中的.ID.怎么让他从1开始计算...因为以前的表中.ID.都很大了
wzy_love_sly 2007-12-11
  • 打赏
  • 举报
回复
selct * into b from a where 军长>司令

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧