select into from和insert into select
生活随笔
收集整理的這篇文章主要介紹了
select into from和insert into select
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
select into from 和 insert into select都是用來復制表,兩者的主要區別為:select into from 要求目標表不存在,因為在插入時會自動創建;insert into select? 要求目標表存在
insert into select語法:
Insert into Table2(field1,field2,...) select field1,field2,... from Table1
注意:
- (1)要求目標表Table2必須存在,并且字段field,field2...也必須存在
- (2)注意Table2的主鍵約束,如果Table2有主鍵而且不為空,則 field1, field2...中必須包括主鍵
- (3)注意語法,不要加values,和插入一條數據的sql混了,不要寫成:Insert into Table2(field1,field2,...) values (select value1,value2,... from Table1)
- (4)由于目標表Table2已經存在,所以我們除了插入源表Table1的字段外,還可以插入常量。
select into from語法:
SELECT field1,?field2 into Table2 from Table1
注意:
復制出來的table只是復制了數據,表的屬性設置是沒有復制的,例如主鍵、索引等
?
轉自:http://www.studyofnet.com/news/182.html
?
轉載于:https://www.cnblogs.com/tjtest/p/7678484.html
總結
以上是生活随笔為你收集整理的select into from和insert into select的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ssm在线视频教育网站
- 下一篇: mysql报错注入实战_MySQL手工注