2011-03-23

[MSSQL]兩個insert的語法

1.將view或是tableB的資料匯到table A


insert into tableA (field1,field2,field3)
select F1,F2,F3 from
tableB
where F4=0

這個方式之前就有了,在這只是記錄一下.

 

2.insert大量資料 (new feature of SQL 2008)


insert into tableA (field1,field2,field3) 
values
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc')


這個是SQL 2008的新功能.


不過用這樣的語法,一次最多只能新增1000筆.


如果要一次新增更多,可以使用BULK INSERT.


 


參考資料:


SQL SERVER – 2008 – Insert Multiple Records Using One Insert Statement – Use of Row Constructor
http://blog.sqlauthority.com/2008/07/02/sql-server-2008-insert-multiple-records-using-one-insert-statement-use-of-row-constructor/


BULK INSERT to table with specific columns
http://beyondrelational.com/blogs/madhivanan/archive/2010/03/17/bulk-insert-to-table-with-specific-columns.aspx

2011-03-21

[Asp.Net]在沒有SMTP的情況下確認發信的程式

.Net 2.0之後提供了一個specifiedPickupDirectory的功能,
讓你在沒有SMTP server的情況下使用資料夾來儲存發信的內容.

使用方式就是在web.config中加入以下的設定

<system.net>
 <mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
   <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
  smtp>
 mailSettings>
system.net>

設定完後,發送的信件就會存在指定的資料夾中.

update [2012/02/23] :

如果你是使用在.net 4.0的話,有可能設定完後出現下面這錯誤

The SMTP host was not specified.

這是個已知的問題 :
http://connect.microsoft.com/VisualStudio/feedback/details/539160/smtpclient-reports-invalidoperationexception-when-disposed-immediatelly-after-sending-mail-and-pickup-directory-is-used

而臨時的解決的方式是在Smtp的tag下加個


<network host="localhost" />

完整範例 :
<system.net>
 <mailSettings>
   <smtp deliveryMethod="SpecifiedPickupDirectory">
     <network host="localhost" />
     <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
     smtp>
 mailSettings>
system.net>



windows 11 不使用微軟帳號登入

試過"斷網路", 試過"用無效的email登入失敗" 最後還是改registry最好用...  在安裝畫面中, 按下 Shift+F10開啟命令提示字元視窗 然後輸入regedit 切換到 HKEY_LOCAL_MACHINE\Softw...