Eri*_*ric 23 sql t-sql ssms sql-server-2008
在我们的数据库中,有一个表有80多个列.它有一个主键,并打开标识插入.我正在寻找一种方法来插入此表中的每一列除了来自不同数据库中相同表的主键列之外.
这可能吗?
kd7*_*kd7 52
你可以很容易地做到这一点:
-- Select everything into temp table
Select * Into
#tmpBigTable
From [YourBigTable]
-- Drop the Primary Key Column from the temp table
Alter Table #tmpBigTable Drop Column [PrimaryKeyColumn]
-- Insert that into your other big table
Insert Into [YourOtherBigTable]
Select * From #tmpBigTable
-- Drop the temp table you created
Drop Table #tmpBigTable
Run Code Online (Sandbox Code Playgroud)
如果您在"YourOtherBigTable"中有Identity Insert On并且列完全相同,那么您将没问题.
归档时间: |
|
查看次数: |
46729 次 |
最近记录: |