欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

必須會(huì)的SQL語句(三) 數(shù)據(jù)插入

 更新時(shí)間:2015年01月03日 01:11:23   投稿:mdxy-dxy  
這篇文章主要介紹了sqlserver中數(shù)據(jù)插入的sql語句,需要的朋友可以參考下

1.規(guī)范一些使用插入語句的小規(guī)范

  1)中文字符串前 最好 加一個(gè)N
  2)列名用中括號(hào) 擴(kuò)起來   像這樣  [列名]
 
2.常規(guī)寫法

Insert into tableName
( [column1] , [column2] )
values
(N'中文','11ds')
 
3.多行一條語句插入多行

insert into 表名 ([列1],[列2])
     select  '值1','值2' union all     --這里呢,union 和 union all的 區(qū)別
                                                      --主要是對(duì)于重復(fù)值得處理,union 會(huì)過濾掉重復(fù)行,而union all會(huì)全插進(jìn)去
     select  '值3','值4' union         
     select  '值5','值6'
 
4.復(fù)制到新表 將原有表中的數(shù)據(jù)復(fù)制到一個(gè)不存在的新表中

  select * into newtable from oldtable
  --僅復(fù)制表結(jié)構(gòu)如何做呢?
select * into newtable from oldtable where 1<>1
select top 0 * into newtable from oldtable 
 
5.插入其他表的數(shù)據(jù)  向一個(gè)已有表中,復(fù)制其他表的數(shù)據(jù)

insert into tablename(column,column2)
      select column,column2 from oldtable
 
6.強(qiáng)行寫入 強(qiáng)行寫入標(biāo)識(shí)字段。

--對(duì)于已經(jīng)設(shè)置自動(dòng)增長的列,默認(rèn)情況我們無法對(duì)其輸入值。
--可以用一下語句去強(qiáng)行寫入。
 
--1)開啟添加,(解除添加的限制)
Set indentity_insert tablename On
--2)可以手動(dòng)插入id了
insert into 表明 (id,name) values ('1002','大二')
--3)關(guān)閉手動(dòng)插入
Set indentity_insert tablename off

相關(guān)文章

最新評(píng)論