首頁  >  文章  >  資料庫  >  sql語句 插入語句

sql語句 插入語句

伊谢尔伦
伊谢尔伦原創
2016-12-03 10:47:312915瀏覽

1.規範一些使用插入語句的小規範

  1)中文字串前最好加一個N

  2)列名用中括號擴起來   如此  [列名]

 

Insert into tableName

( [column1] , [column2] )

values

(N'中文','11ds')

語單詞

[列1],[列2])

     select  '值1','值2' union all     --這裡呢,union 與union all的區別🠎                                 --主要為重複值得處理,且union 會過濾掉重複行,而union all會全插進去

     select  '值3','值4' union         

         

  有表中的資料複製到一個不存在的新表中

  select * into newtable from oldtable

  --僅複製表結構如何做呢?

select * into newtable from oldtable where 11

select top 0 * into newtable from oldtable

 

5.插入其他表格的資料來源tablename(column,column2)

      select column,column2 from oldtable

 

6.強制寫入 強行寫入識別欄位。

--對於已經設定自動增長的列,預設情況我們無法對其輸入值。

--可以用一下語句去強行寫入。

 

--1)開啟添加,(解除添加的限制)

Set indentity_insert tablename On

--2)可以手動插入id了

( '大二')

--3)關閉手動插入

Set indentity_insert tablename off

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn