zoukankan      html  css  js  c++  java
  • INSERT INTO vs SELECT INTO

    What is the difference between using

    SELECT ... INTO MyTable FROM...

    and

    INSERT INTO MyTable (...)

    SELECT ... FROM ....

    ?

    From BOL [ INSERTSELECT...INTO ], I know that using SELECT...INTO will create the insertion table on the default file group if it doesn't already exist, and that the logging for this statement depends on the recovery model of the database.

    1. Which statement is preferable?
    2. Are there other performance implications?
    3. What is a good use case for SELECT...INTO over INSERT INTO ...?

    Edit: I already stated that I know that that SELECT INTO... creates a table where it doesn't exist. What I want to know is that SQL includes this statement for a reason, what is it? Is it doing something different behind the scenes for inserting rows, or is it just syntactic sugar on top of a CREATE TABLEand INSERT INTO.

    1. They do different things. Use INSERT when the table exists. Use SELECT INTO when it does not.
    2. Yes. INSERT with no table hints is normally logged. SELECT INTO is minimally logged assuming proper trace flags are set.
    3. In my experience SELECT INTO is most commonly used with intermediate data sets, like #temptables, or to copy out an entire table like for a backup. INSERT INTO is used when you insert into an existing table with a known structure.
  • 相关阅读:
    Socket
    字符串,byte,字典转换整理
    1-嵌入式面试题库
    10-FreeRTOS 队列
    9-FreeRTOS API获取任务使用CPU时间
    7-代码区 | 常量区 | 静态区(全局区) | 堆区 | 栈区
    8-FreeRTOS任务API
    7-FreeRTOS时间片进行任务调度
    6-C指针
    用Union体测试处理器大小端
  • 原文地址:https://www.cnblogs.com/bi-info/p/6222674.html
Copyright © 2011-2022 走看看