select into @
时间: 2023-10-02 19:06:28 浏览: 85
insert into select和select into的使用和区别介绍
SELECT INTO是一种SQL语句,用于将查询结果插入一个新的表中。在使用SELECT INTO之前,可以先判断临时表是否存在,如果存在则先删除,然后再执行SELECT INTO语句。例如,可以使用以下语句进行判断和执行SELECT INTO操作:
```sql
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
SELECT * INTO #temp FROM sysobjects
SELECT * FROM #temp
```
这个语句会先判断名为'#temp'的临时表是否存在,如果存在则删除,然后将'sysobjects'表中的所有数据插入到'#temp'表中,并最后查询'#temp'表的内容。通过这种方式,可以在使用SELECT INTO之前确保临时表的清空和创建,确保结果的准确性。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [把存储过程结果集SELECT INTO到临时表](https://blog.csdn.net/weixin_34387468/article/details/85605762)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [SQL语法之SELECT INTO 语句](https://blog.csdn.net/westos_yanzheng/article/details/126418000)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文