关于临时表的主键或索引

tigerjacky 2004-12-24 02:42:36
有语句
select col1,col2 into #tmptable from tablea
如果我想定义#tmptable的主键或者索引,能一步到位吗?
...全文
107 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigerjacky 2004-12-27
  • 打赏
  • 举报
回复
自己顶
NinGoo 2004-12-24
  • 打赏
  • 举报
回复
不能。可以先建好临时表,加上主建后再insert数据

select col1,col2 into #temptable from tablea where 1=2

alter table #temptable add constraint c_col1 PRIMARY KEY (col1)

insert into #temptable select col1,col2 from tablea

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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