2009年12月23日 星期三

有關資料庫的索引運用,指定索引!

查看查詢式,所有的條件式鍵值欄位,皆有列入索引,
但不知為何,SQL還是採用「掃描整個叢集索引」??
因此採用指定索引查詢,其查詢反應時間由原本的30秒下降至1秒之內!
查詢回應時間大幅改善..


雖然指定索引查詢,效能獲得很大的改善,但是否有什麼後遺症,目前不得而知!

vco_schedule_tab 已建置的索引
IX_vco_schedule_tab nonclustered located on PRIMARY comid, sdate, pflag

PK_vco_schedule_tab clustered, unique, primary key located on PRIMARY vocfile




2009年12月20日 星期日

D-LINK TDS WEB

前陣子由中文網頁下載 DFL-210 的 firmware,屢試不爽,始終遭遇到錯誤訊息!
Firmware upload failed. There is something wrong with the firmware package. Please download the firmware image from the D-Link support website and try again.
花費不少時間,(D-LINK 的客服忙的哩!),總算得到工程師的技術支援!
要求去如下網址下載 firmware http://tsd.dlink.com.tw
弄來弄去,原來中文網頁的firmware放錯了!
我想 tsd.dlink.com.tw恐怕才是他們第一手維護的資料,以後直接參考此網址吧!

2009年12月15日 星期二

看到一些文章,在討論 sql nolock 選項

看到一些文章,在討論 sql nolock 選項
不知各位是否有用過?
我想它不見得是對當下的查詢式回應時間能有顯著的改善, 但對降低整體sql server 的負擔,是有幫助的!
針對一些「過往資料的呈現」,或是「資料統計運算的來源」的查詢 或許 加上 with (nolock) 是有幫助的!
若各位有運用,並感覺有幫助,請提出來分享一下吧!

SELECT COUNT(UserID)
FROM EMPLOYEE WITH (NOLOCK)
JOIN WORKING_GROUP WITH (NOLOCK) ON
EMPLOYEE.UserID = WORKING_GROUP.UserID

sql 索引??評估執行計劃!

select *
from car_workid_ref_tab
where idate ='2009-10-05 00:18:44.653'
-- 我訝異如下的3組查詢式,SQL會採取不同的查詢計劃,
-- 就竟是什麼規則,不得而知,但似乎和預期的量有關!
-- 預期量大時,竟然採掃描整個叢集索引..(2),(3)
-- 意外的,查詢反應時間反而不如預期!!因idate並非叢集索引。

-- (1)
select *
from car_workid_ref_tab
where idate <= dateadd(m,-4,getdate())
-- (2)
select *
from car_workid_ref_tab
where idate <= dateadd(m,-3,getdate())
-- (3)
select *
from car_workid_ref_tab
where idate <= dateadd(m,-2,getdate())

2009年10月22日 星期四

想在IDENTITY欄位插入自定數值

因故一些資料的轉換,資料在資料表之間倒來倒去,
但希望插入舊有的IDENTITY值於IDENTITY欄位中...
因而研究了一下 「SET IDENTITY_INSERT」這個指令

確實能將小於目前的IDENTITY NO 加入表格中,符合需求!
但若「想在IDENTITY欄位插入自定數值」,則沒有辦法嘍!

允許將明確的值插入資料表的識別欄位中
如果輸入的值大於資料表目前的識別值,SQL Server 會自動利用新插入的值來作為目前的識別值。

2009年10月19日 星期一

2009年10月15日 星期四

Excel 2000 裡「SYLK:檔案格式無效」


http://simon.unipiece.info/

Excel 2000 裡「SYLK:檔案格式無效」

之前在駐點的公司曾碰到一個很神奇的狀況,有一位 User 反應說在 Excel 打不開 .CSV 的報表,而且會一直出現一個錯誤訊息:「SYLK 的檔案格式無效」。

說來奇怪,這個檔案明明就是純文字轉成 CSV 的檔案,標準的資料用逗點做分隔而已,但笨笨的 Excel 2000 卻一直硬是把這個 CSV 的報告當做 SYLK 格式的檔案(我用 Notepad 開都沒有問題 )

在請教過 Google 大神後,我找到了答案(原本的網址已經不見了),我引用原文如下:

Something I stumbled across trying to return a *.csv file to Excel 2000: If the very first text in the file is "ID", Excel will ignore the file extension and attempt to read the file as a SYLK (Symbolic Link) file format.

Just wanted to share this hidden tidbit, in the off-chance that it may save somebody else pain.

-- Rob Storrs, February 15, 2001

大致上的意思是:只要 CSV 的檔案是以「ID」開頭的,Excel 就會把它當做是 SYLK 的檔案格式(真是聰明的程式),我自己實驗了一下,真的只要把 ID 二個字改掉,就沒有問題了,真是令人絕倒啊!

註一、
SYLK 即為 Symbolic Link 的縮寫。
在 Excel 中,SYLK 類型的檔案含有 macro,假若在 Excel 97 或 Excel 2000 內開啟此類型檔案,檔案內的 macro 會在未通知使用者的情形下被執行,這個 macro 命令可以是使用者在電腦上所能執行的任何命令。

註二、
這個問題在 Office 2003 裡已經解決,但仍會出現警告視窗,警告的內容還是一樣!所以放上來記錄一下。

2009年10月13日 星期二

無法寄送郵件 insufficient dis...


使用者界面遭遇到如上問題,查察mail server df,
確實/var/spool/mqueue 空間不足,僅剩 %1。
ls -alt -t /var/spool/mqueue

奇怪的是,這些空間,怎沒有被mail server給主動回收呢?!

2009年9月24日 星期四

table exclusive lock

依如下範例測試,不知是否表示sql server執行了table exclusive lock

執行順序
ConnA 04,05,06,07
ConnB 02 --> lock 無執行結果
ConnA 08,09
ConnB --> 因ConnA Commit,ConnB 回傳執行update的結果,被Trigger機制拒絕異動!






http://neo_lin_42.blog.ithome.com.tw/post/620/6287

2009年9月17日 星期四

溫故卻無知新--唉!這就是工作.....<4>

設定內部DNS,誤將mail server ip 指向 smtp-gw的效果

From: <SMTP_GW@office.mobile.com.tw>
Date: Thu, Sep 17, 2009 at 6:01 PM
Subject: Returned mail
To: iidp00u@gmail.com


--- The message cannot be delivered to the following address. ---

support@taxi123.tw Address loop detected. Service will not connect to itself.



溫故卻無知新--唉!這就是工作.....<3>

忘了設定內部DNS,SMTP-GW找不到mail server 的效果

From: <SMTP_GW@office.mobile.com.tw>
Date: Thu, Sep 17, 2009 at 5:55 PM
Subject: Returned mail
To: iidp00u@gmail.com


--- The message cannot be delivered to the following address. ---

support@taxi123.tw Remote host not found.



溫故卻無知新--唉!這就是工作.....<2>

忘了設定SMTP-GW要處理taxi123.tw網域的效果

From: Mail Delivery Subsystem <mailer-daemon@googlemail.com>
Date: Thu, Sep 17, 2009 at 5:37 PM
Subject: Delivery Status Notification (Failure)
To: iidp00u@gmail.com


This is an automatically generated Delivery Status Notification

Delivery to the following recipient failed permanently:

support@taxi123.tw

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 support@taxi123.tw ...Relaying denied (state 14).


溫故卻無知新--唉!這就是工作.....<1>

忘了設定外部DNS的A,MX Record的效果

From: Mail Delivery Subsystem <mailer-daemon@googlemail.com>
Date: Thu, Sep 17, 2009 at 5:30 PM
Subject: Delivery Status Notification (Failure)
To: iidp00u@gmail.com


This is an automatically generated Delivery Status Notification

Delivery to the following recipient failed permanently:

support@taxi123.tw

Technical details of permanent failure:
DNS Error: DNS server returned answer with no data


2009年9月11日 星期五

DFL-210 CLI SET IP ADDRESS

DFL-210:/> set Address IP4Address InterfaceAddresses/lannet address=192.168.4.0/

2009年9月10日 星期四

OUTLOOK 2000 信件檔超過2GB,無法存取或開啟

OUTLOOK 2000 信件檔超過2GB,無法存取或開啟

指派給:
是否已經核對?否
核對者:
核對日期:2009-09-10 08:17:34
常見問答分類:

參考微軟官網,搜尋關鍵字「超大PST和OST檔案的裁工具」

兩工具如下:

  1. SCANPST.EXE
  2. 2GB152.EXE (解壓縮後,可得5個檔案,pst2gb...)

根據文件,指出更新程式可避免Outlook允許.pst檔超過2GB的最大容量。

  1. Office 2000 SR-1/SR-1a

其它官網資訊:

1. 從下列「Microsoft 下載中心」連結下載工具:
http://www.microsoft.com/downloads/details.aspx?FamilyID=B33B1DFF-6F50-411D-BBDF-82019DDA602E&amp;displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=B33B1DFF-6F50-411D-BBDF-82019DDA602E&amp;displaylang=en)
2. 將 2gb152.exe 檔案解壓縮到空資料夾。您應該可以看到下列五個檔案:
Msstdfmt.dll
Msvbvm60.dll
Pst2gb.exe
Readme.rtf
Readme.txt
3. 啟動 Pst2gb.exe 程式。
4. 按一下 [Browse] 以選取檔案超大的 .pst 檔案,再按一下 [開啟]
5. 按一下 [Create],並選取要建立之截斷資料檔的名稱及位置,然後按一下 [存檔]
6. 輸入要在 .pst 檔中截斷的資料量。這並非您所使用的正確數量。最好是使用 20 到 25 MB,但您也可以截斷多一點或少一點。例如,如果您截斷 25 MB 的資料且此處理仍能繼續,則請重複此處理,並只從原始大小的 .pst 檔中截斷 15 MB。如果這樣也沒問題,請再試試 5 MB。如果 25 MB 無法作用,請重複此處理,並從原始大小的 .pst 檔中截斷 35 MB。如果這樣還是無法作用,請再增加數量,直到處理成功為止。
7. 針對縮小後的 .pst 檔執行「電子郵件信箱修復工具」(Scanpst.exe 檔)。
8. 在 Outlook 中開啟修復後的 .pst 檔。
9. (這個步驟只是建議使用,非絕對必要) 如果檔案開啟了,請以滑鼠右鍵按一下 .pst 的根資料夾,按一下 [內容],再按 [開始壓縮] 以啟動壓縮。此大小檔案的壓縮過程可能需要花費大約 4-8 個小時。
10. 如果檔案無法開啟,請捨棄截斷後的 .pst 檔,並以原始的 .pst 檔重複此處理。截去比第一次嘗試截斷更多的資料,再試一次此處理。
11. 根據您的 Outlook 版本安裝下列更新程式或 Hotfix。如果要執行這項操作,請檢視「Microsoft 知識庫」中的下列文件:
245025 (http://support.microsoft.com/kb/245025/) 如何取得並安裝 Office 2000 SR-1/SR-1a 更新
這些更新程式可避免 Outlook 允許 .pst 檔超過 2 GB 的最大容量。請使用下列方式之一管理 .pst 檔的大小:

使用一個以上的 .pst 檔。
使用封存功能。
將附件儲存在檔案系統資料夾,並從郵件中加以刪除。


2009年9月9日 星期三

比較 datetime 資料型態,別忘了0.999秒

看似相同的查詢式,查詢效率大不同



直想不出好的文句來述敘此現象的原由,粗操的說..
「經過convert後的資料,其排列的順序不見得和原資料型態相同,此失去索引提供的好處。」,也因此,查詢效率大不同!
另外,convert,確實也產生了不少的查詢成本。


總歸一句,
<1> 不要企圖將被搜尋資料欄位,將其轉換型別來等同於查詢式的條件。
<2> 而是要將查詢式的條件轉換,使其等同於欄位定義的資料型別。

2009年9月8日 星期二

SQL SERVER TRANSACTION 交易機制


時間序列

Update 1筆資料列,同1個欄位

Connection A

Connection B

<1>

Begin Tran

 

<2>

Select

 

<3>

 

Begin Tran

<4>

 

Select

<5>

 

Update (Success)

<6>

Update (未執行)

 

<7>

 

Commit Tran

<8>

Update (Success)

 

<9>

Commit Tran

 

 

    在未指定任何參數的情況下,select 並不會造成「鎖定」,而是在update時,才會造成以「資料列鎖定」。

    當先執行updateconnection,完成commit rollback的同時,另一connection update才得以繼續執行!

     

2009年8月26日 星期三

sqlserver 2005 取得 @@identity




2005 :
sql = "Insert into tr_mem_comid_tab (" &_
" memsn, cname, dname, cardid, empid, email" &_
", uid, ctime, uid_ref" &_
") output inserted.csn Values(" &_
memsn &_
", '" & fm.Item("cname") & "'" &_
", '" & fm.Item("dname") & "'" &_
", '" & fm.Item("cardid") & "'" &_
", '" & fm.Item("empid") & "'" &_
", '" & fm.Item("email") & "'" &_
", 'WEB'" &_
", getdate()" &_
", '" & Session("myip") & "'" &_
")"
sql = "delete from tr_mem_comid_tab" &_
" output deleted.cardid where csn=" & csn

2009年8月25日 星期二

設計資料表欄位,留意『現在式狀態』『過去式歷程』兩種類型的資料表

設計資料表欄位,或進行資料表參照時,要留意『現在式狀態』『過去式歷程』兩種類型的資料表 因為,這兩類型的資料有時是不能參照的, 例如:通訊錄 vs 郵寄歷程 乍看之下,郵寄歷程的發送對象,可參照通訊錄中的鍵值; 但隨者時間的前進,通訊錄是有可能異動或更新的,此時,郵寄歷程所參照出來的資料,將會不正確。

2009年8月21日 星期五

NULL害死人不償命

NULL 值是不能比較,或與任何值相加減的~



很小的程式、很簡單的問題,卻禍不單行,煮成大雜燴包,這難吃的包,還是得往肚裡吞,不然就回家食自己~ (當廚餘丟掉的話~)

2009年8月17日 星期一

奇怪的是,Gmail 收到,但 Hinet 就是收不到~

開發人員反應,說他的郵件一直不能寄給特定的信箱(郵件主機)
於是我就請他分別寄給我 Hinet 和 Gmail 兩個信箱..
奇怪的是,Gmail 收到,但 Hinet 就是收不到~

幾經測試與查察,終於發現原因:
  • 原因在於 寄件者所宣稱的網域名稱不存在,
  • 推測Hinet有利用網域名稱反查的機制,
  • 因此,該封測試郵件被丟棄於無形。

這讓我想到,以前處理過的一案例, 曾有人因modem無法撥接成功,求助於我, 我於現場查看設備燈號,一切皆正常,因此,認定是modem的問題而送修。 送修時,店員拿出新品,要換貨時,赫然發現,送修的Adapter和Modem並非同一組設備,此時,真相才終於大白。

使用者誤插其它設備的Adapter,因電壓不符,而使Modem無法運作!

事後看來,這些問題,是再芝麻也不過,不過,卻依然隨機起舞,耗費不少時間!

2009年8月13日 星期四

希望在 select 出的資料上,自動加上流水號


為了讓同一批次insert into表格的資料,有獨立的流水號

希望在 select 出的資料上,自動加上流水號



<1> 嘗試在select 子句上,看有無參數可達成如是效果,查無!

<2> 採Cursor 方式,是最直覺的解決方案,不過擔心效能不彰!

<3> 最後,採select ....into #tmptab 的方式,
'sn'=identity(int,1,1) 來產生流水號,最後再append至正式表格
當 SELECT 陳述式中有 INTO 子句時,才能使用 IDENTITY 函數。

2009年8月5日 星期三

word 自動把第一個字母變成大寫 ><

MS WORD 有時太自動自發,也很困擾,總算找到可讓它不自動的選項了
關鍵字:工具->自動校正

2009年7月27日 星期一

運用OUTLOOK 2000,實作行事曆維護及工作排程

根據「時間管理-給系統管理者 Time Management for System Administrators」這本書所提及的觀念,我於OUTLOOK 2000 中實作了行事曆維護及工作排程。

主要觀念,是將工作項目以
  • 優先性及建立時間2鍵值進行排序
  • 優先性較高或建立時間較早的,排在前面,列入每天的執行項目
經過一段時間的運用,發現OUTLOOK的機制,遠比預期的高出許多,
  • 除了運用「優先性及建立時間2鍵值排序」外,
  • 我再輔以「類別」及群組的機制,以及 "drag and drop" 的功能,
使得工作得以快速建立,並且一目了然。

唯,欠缺子工作的機制,甚為可惜,對於同一項目所衍生的工作,變的不易追蹤及呈現。

另外,雖然OUTLOOK使我的待工作事項一目了然,但對於該作什麼,似乎沒什麼幫助, 因為,每天就竟該作什麼;每天就竟什麼優先,深深的被大環境左右著。

運用行事曆排程工作,只是時間管理中的一環,實驗證實,沒有全盤的運用,容易功虧一簣。不過,拿來匯整年度工作報告,或是週報告,都非常好用!

時間是珍貴的東西,對於系統管理者而言尤甚。沒有其他工作會把那麼多領域的事情,一次推給一個人作。使用者經常以他們的請求干擾你,讓你無法完成經理指派給你的長期專案;還有你的電腦就是不聽話,總是在最關鍵的時刻與你耍脾氣。儘管你精通職務上的技術,但是仍然發現必須在晚上和週末加班,只是為了達成一大堆要求。這只會隨著時間,增加自己的壓力。

本書討論的策略,不但幫你解決日常工作,還有能力處理無法避免所產生的突發狀況。作者將自己長期的職業生涯,諸如,支援桌面應用、伺服器管理、以及安全和軟體開發等等,詳實地舉例說明在本書中。這意味著,你將得到有實戰經驗的建言,而非象牙塔般,從未在混沌的網路工作過的陳腔濫調。

在其他技術上,你將學習如何:

  • 管理干擾
  • 消除時間的浪費
  • 保持有效的行事曆
  • 將經常發生的事情變成例行公事
  • 專注在手邊的工作
  • 以客戶預期的事排列優先順序
  • 文件化和自動化處理以便快速執行

確實掌握 iptables 運作基本觀念















了解這份文件,確實掌握 iptables 運作基本觀念

2009年7月22日 星期三

如何製作可傳入參數的執行檔

將定義變更儲存至含有大量資料的資料表,可能會需要相當長的時間。

重新定義資料表的schema時,在既有欄位中新增欄位(插入),可能涉及實體資料的排列順序,sql 2005 會出現如下提醒,而且真的做了好一陣子!而且,就其敘述,「將無法存取資料表中的資料」,茲事體大,在營運系統就沒採插入的方式新增欄位了!

/*
2009年7月22日下午 12:26:53
使用者: sa
伺服器: 172.17.100.14
資料庫: xxxxdb
應用程式:
*/

'xxxx_tab' 資料表
- 將定義變更儲存至含有大量資料的資料表,可能會需要相當長的時間。儲存變更的期間,將無法存取資料表中的資料。

但若是將新增的欄位,附加於既有欄位的最後面,則不會出現任何提醒,並且儲存異動,也一下就好了!

2009年7月15日 星期三

Cursor Optimization Tips

本來以為 "INSENSITIVE" 、 "KEYSET""STATIC" 選項,有助於系統效能,結果,發現..會錯意了..應避免使用之~

Cursor Optimization Tips

  • Try to avoid using SQL Server cursors, whenever possible.
    SQL Server cursors can results in some performance degradation in comparison with select statements. Try to use correlated subquery or derived tables, if you need to perform row-by-row operations.


  • Do not forget to close SQL Server cursor when its result set is not needed.
    To close SQL Server cursor, you can use CLOSE {cursor_name} command. This command releases the cursor result set and frees any cursor locks held on the rows on which the cursor is positioned.


  • Do not forget to deallocate SQL Server cursor when the data structures comprising the cursor are not needed.
    To deallocate SQL Server cursor, you can use DEALLOCATE {cursor_name} command. This command removes a cursor reference and releases the data structures comprising the cursor.


  • Try to reduce the number of records to process in the cursor.
    To reduce the cursor result set, use the WHERE clause in the cursor's select statement. It can increase cursor performance and reduce SQL Server overhead.


  • Try to reduce the number of columns to process in the cursor.
    Include in the cursor's select statement only necessary columns. It will reduce the cursor result set. So, the cursor will use fewer resources. It can increase cursor performance and reduce SQL Server overhead.


  • Use READ ONLY cursors, whenever possible, instead of updatable cursors.
    Because using cursors can reduce concurrency and lead to unnecessary locking, try to use READ ONLY cursors, if you do not need to update cursor result set.


  • Try avoid using insensitive, static and keyset cursors, whenever possible.
    These types of cursor produce the largest amount of overhead on SQL Server, because they cause a temporary table to be created in TEMPDB, which results in some performance degradation.


  • Use FAST_FORWARD cursors, whenever possible.
    The FAST_FORWARD cursors produce the least amount of overhead on SQL Server, because there are read-only cursors and can only be scrolled from the first to the last row. Use FAST_FORWARD cursor if you do not need to update cursor result set and the FETCH NEXT will be the only used fetch option.


  • Use FORWARD_ONLY cursors, if you need updatable cursor and the FETCH NEXT will be the only used fetch option.
    If you need read-only cursor and the FETCH NEXT will be the only used fetch option, try to use FAST_FORWARD cursor instead of FORWARD_ONLY cursor. By the way, if one of the FAST_FORWARD or FORWARD_ONLY is specified the other cannot be specified.


另外,CURSOR的選項,有些是相衝突的,該篇文章中,有用表格整理,一目了然!! "Cursor Options Compatibility"



參考資料:http://www.mssqlcity.com/

Difference between Static Cursors and Dynamic Cursors

Difference between Static Cursors and Dynamic Cursors

* A Static Cursor doesn't reflect data changes made to the DB once the ResultSet has been created whereas a Dynamic Cursor reflects the changes as and when they happen.
* A Static Cursor is much more performant than a Dynamic Cursor as it doesn't require further interaction with the DB server.
* A static cursor supports both Relative and Absolute Positioning whereas a Dynamic Cursor supports only Relative Positioning.
* A Static Cursor can be used for Bookmarking purposes as the data returned is static whereas a Dynamic Cursor can't be used for the same.

Static Cursor: A Database Cursor is called a Static Cursor if it captures the snapshot of data only at the time when the ResultSet (or Recordset in case of MS SQL Server) is created with no further DB interaction afterwards. And hence a Static Cursor will be unaware of any data changes made into the database after the ResultSet has been created. A Static Cursor facilitates scrolling through the static ResultSet and it supports both absolute and relative positioning. Reason being, the ResultSet is static and hence the cursor can always be sure of the position of all the records/rows. Relative positioning can be specified in terms of offsets from the current, top or bottom rows.

Dynamic Cursor: A Dynamic Cursor is the one which reflects all the data changes made into the database as and when they happen. This may require continuous re-ordering of data in the ResultSet due to the database changes and hence it's much more expensive than a Static Cursor. The possible re-ordering of records in the ResultSet doesn't allow a Dynamic Cursor to support absolute positioning as it can't be sure of the absolute position of a record/row in the ResultSet. Hence a Dynamic Cursor only supports relative positioning. Furthermore a Dynamic Cursor doesn't support Bookmarks for the obvious reasons.


參考來源:http://geekexplains.blogspot.com

2009年7月14日 星期二

只有 DECLARE CURSOR 才允許 FOR UPDATE 子句。

伺服器: 訊息 1003,層級 15,狀態 2,行 3
行 3: 只有 DECLARE CURSOR 才允許 FOR UPDATE 子句。

2009年7月13日 星期一

@@TRANCOUNT

例用 @@TRANCOUNT 來判斷預存程序目前已經開啟了幾個交易。 如果這個變數在預存程序中並沒有任何的變動,我們並不需要在預存程序中使用Commit 或 Rollback。

sysname 型別

sysname 是一個系統支援的使用者自訂資料型別,為 nvarchar(128) 的同義資料表,用來參考資料庫物件名稱。

系統預存程序

系統預存程序會被儲存在系統資料庫(master 和 msdb)中,而且它們名稱是以sp_做為開頭。
這個字首並不只是個命名方式。它還告訴了伺服器這個預存程序被儲存在master資料庫中,而且使用者並不需要加上資料庫的名稱,就可以在所有的資料庫中使用這個預存程序!

2009年7月12日 星期日

使用 sp_addmessage 定義自己的錯誤!


其中,16,1 分別表示這個錯誤的「嚴重等級」和「狀態」
with log,可將錯誤輸出至Windows EventLog中

2009年7月7日 星期二

2009年7月6日 星期一

SET vs SELECT when assigning variables

The article is well worth the read, but here are the main points:

  1. SET is the ANSI standard for variable assignment, SELECT is not.
  2. SET can only assign one variable at a time, SELECT can make multiple assignments at once.
  3. If assigning from a query, SET can only assign a scalar value. If the query returns multiple values/rows then SET will raise an error. SELECT will assign one of the values to the variable and hide the fact that multiple values were returned (so you'd likely never know why something was going wrong elsewhere - have fun troubleshooting that one)
  4. When assigning from a query if there is no value returned then SET will assign NULL, where SELECT will not make the assignment at all (so the variable will not be changed from it's previous value)
  5. As far as speed differences - there are no direct differences between SET and SELECT. However SELECT's ability to make multiple assignments in one shot does give it a slight speed advantage over SET.

Take a look at the complete article to see Vyas' complete tests to get the entire picture:
[http://vyaskn.tripod.com/differences_between_set_and_select.htm]

Reference
http://ryanfarley.com/blog/archive/2004/03/01/390.aspx

2009年7月5日 星期日

除BUG的同時,也在寫BUG..

解決程式中的缺陷通常要比找出這些缺陷容易許多,但不要把這個皆段看得太過簡單。當程式發展循環來到這個階段時,如果產品的出貨日期已經逼近,你也許會被要求盡快修正。請不要急著修正:這通常會讓開發者在修正原有的錯誤時,又產生新錯誤。(戚戚..)這樣的錯誤通常並不是因為粗心或缺乏耐心所導致,而是來自於修正和出貨所帶來的巨大壓力。(戚戚..)

SQL Server 特別容易受到急於解決問題所產生的新問題所影響,因為預存程序只要一個動作就能夠被編譯和儲存。如果你試者在生產環境中解決缺陷,那麼整個生產環境可能會受到更嚴重的傷害。

雖然你還是能夠在生產環境進行修正,但是比較好的作法是往後退一步、花一點時間來瞭解問題、然後試著在生產環境外解決問題。

如果測試環並不存在,或是測試環境過於老舊,你也許想要節省一些時間而盡快的將問題修正。(戚戚..)然而,當你這麼做之前,你必須考慮如果在修正的過程中發生了其他的錯誤,系統資源將會有什麼樣的改變,以及如何還原。無論你做了什麼事,你都無法快速而輕易的將系統加以還原。

因此,很顯而易見的:你的確需要一個測試環境!

摘自:McGraw-Hill SQL SERVER 2000 預存程序 程式設計

MSSQL sp_helptext

在舊書新讀的過程中,撿到這支系統的 store procedure, sp_helptext
以前卻都沒用過,但它卻對我目前的現況非常有幫助,
我的Client端,僅安裝簡單的SQL Query Analyzer(sql 2000),在部份主機導入sql server 2005後,為了瀏覽主機上的程式碼,都是到本機上,打開笨重的 SQL Server Management Studio(sql server 2005),有了sp_helptext,可以很輕易的瀏覽sql server 2005上的 程式碼嘍!

2009年7月3日 星期五

避免大量且非預期update 或是 delete

為避免前端應用程式開發者,可能對於schema不熟悉,或是一時的疏忽,進而對資料庫進行大量且非預期update 或是 delete,我們通常會在資料表的 Trigger中進行檢核,不允許一筆 statemenet 進行大於一筆record以上的update 或是 delete。
不過,實務上亦衍生出其它問題,當必要性的批次異動,卻也被此Trigger檢核擋了下來,目前正在尋求解決方案,看可否針對特定登入帳號,bypass 此檢合機制!有誰有其它的解決方案嗎?



suser_name()看來可達到上述的效果

2009年7月2日 星期四

MS SQL 自訂函數-資料表值函數



※要留意,在自訂函數中,無法使用暫存資料表 #tmp_tab

關鍵字:MSSQL2005, 資料表值函數

2009年7月1日 星期三

資料庫索引,玩玩看

建置資料庫索引,基本上對於查詢的效率一定是有幫助的,
以下是個簡單的查詢,並例用「評估執行計劃」得到的結果!



cleader 欄位,未建置索引資料前,其查詢費時,相對於批次,約達85%

cleader 欄位,建置索引資料後,其查詢費時,相對於批次,下降至 66%




由評估計劃,亦可了解,叢集所引的效率一定是最好的!

第一次採用MS SQL的自定函數-純量值函數

第一次採用MS SQL的自定函數,可將複雜且一再重複使用的東西模組化,增加程式的可讀性,並且統一維護商業邏輯,蠻好用的!





關鍵字:MSSQL2005, 純量值函數

SQL #tmp_tab vs @var_tab

資料庫的暫存表格 #tmp_tab 和 變數型態的表格 @var_tab
應用上十分相像,就個人而言,比較習慣使用 #tmp_tab

另外,就上述兩項工具,根據心得,列出如下差異性!
  • 兩者身命週期不同,#tmp_tab 依 connection;
    @var_tab 依 batch
  • #tmp_tab 的 schema 可經由 select into 自動建立;
    @var_tab 則需事先宣告


2009年6月30日 星期二

select as table 運用

2009年6月29日 星期一

如何在Google Blogger中使用 SyntaxHighlighter

Blogger
SyntaxHighlighter

Linux 以時間排序檢視檔案

ls -lt -r

-t sort by modification time
-r, --reverse
reverse order while sorting

開放root直接以 telnet 連接上主機

root 不能直接以 telnet 連接上主機:
既然 telnet 不是很安全,自然預設的情況之下就是無法允許 root 以 telnet 登入 Linux 主機的!
但是,事實上, telnet 只是利用一些較為安全的機制來防止 root 登入而已~

所以囉,假如您確定您的環境夠安全(例如您的主機並沒有連上 Internet ),並且想要開放 root 以 telnet 登入 Linux 主機的話,
請直接將 /etc/securetty 更改檔名即可!
[root@test root]# mv /etc/securetty /etc/securetty.bak

這樣一來,root 就可以登入啦!不過,相當的不建議這樣做喔!畢竟不是很安全啦!

此外,您也可以藉由修改 pam 模組來達成同樣的功能!修改 /etc/pam.d/login 這個檔案的第二行設定即可:
[root @test /root]# vi /etc/pam.d/login
#%PAM-1.0
#auth required /lib/security/pam_securetty.so
# 將上面這一行加上 # 註解掉!
auth required /lib/security/pam_stack.so service=system-auth
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_stack.so service=system-auth
password required /lib/security/pam_stack.so service=system-auth
session required /lib/security/pam_stack.so service=system-auth
session optional /lib/security/pam_console.so
如此一來, root 將可以直接進入 Linux 主機了!不過,還是不建議如此做的!

fedora設定預設不進入x windows

vi /etc/inittab
找到這一行
id:5:initdefault:
改成
id:3:initdefault:
就可以了。

SQL 2000 如何像2005一樣可以"暫停" trigger 機制

經過小弟的努力下找到了答案在此提供給各位

alter table XXXX disable trigger triggername

為disable 該trigger

alter table XXXX enable trigger triggername

為enable 該trigger

註冊 windows dll regsvr32.exe

regsvr32.exe -u "C:\Documents and Settings\joey.chen\My Documents\docweb\gzip.dll"
反註冊前面加個-u

有關ActiveX DLL 版本相容問題

VB5.0 中提供了版本相容的選項,使得您在maintain or enhance您的元件功能時,能相容於較早的版本。

您可以選擇「專案」/「Project屬性」/「元件」,在版本相容元件中,有下列三中選項供您選擇:

無相容元件:每當您編譯元件時,新的 type library information 就會重新被產生(包含新的class ID及新的interface ID)。

與專案相容:每當您編譯元件時,重新產生的 type library information,但保留type library identifier,因此測試的專案依然能參照到元件。

與先前版本相容:每當您編譯元件時,只有必要時,才會重新產生新的Class, Interface ID,因此元件編譯時,保留了舊版本的Class Id及Interface ID。

http://support.ceci.org.tw/directory/worldwide/zh-tw/faq/1837.htm

有關Base64 Encode & Decode Lib

Check out http://sevillaonline.com/ActiveX/ . Look for Base64 Encoding
Library, which is simple and free ActiveX DLL written by Alvaro Redondo.
Works great ... I wrapped it in my own VB code for my own purposes. I also
used it successfully from ASP .

2009年6月28日 星期日

MD5的應用

經常伴隨著iso檔出現的MD5檔案的用途是什麼?
延伸檔名.md5的檔案是用來做iso檔的查驗,
它是一種依據iso檔內容計算出來的值,
當你從網站上下載ISO的檔案時若有連這個.md5的檔案,
你可以在linux/Unix的作業系統下使用"md5sum 檔案名稱"來做下載檔案是否完整的確認。
在http://www.linuxiso.org/viewdoc.php/verifyiso.html或
http: //www.fourmilab.ch/md5/可以找到一些關於MD5的相關資訊。
若是要下載windows版的MD5程式可以在http: //www.toast442.org/md5gui.shtml這個網站下載。

Public Key vs Session Key

所以,聰明的人們總是能集優而取:
大量的資料傳送通常使用對稱加密、
而對稱鍵值則用非對稱加密來交換!Bingo~~~

這樣不就解決了便利性與效能的矛盾了嗎? ^_^ 是的,現今許多加密應用軟體,都同時將兩種加密技術應用在一起:

1. 當 client 端連上來之後,從 server 端下載 public key 。
2. Client 端隨機產生用作對稱加密的 session key 。
3. 並使用剛從 server 端下載回來的 public key 作加密,將 session key 送回給 server 。
4. 最後用 session key 作加密,開始傳送加密資料。

當然了,以上只是一個簡單的描述而已,真正的運作會複雜得多,但基本原理則是一樣的。

摘至 http://www.pcnet.idv.tw/pcnet/network/network_enscp.htm

Equal-cost multi-path (ECMP)

Linux 網路頻寬的負載平衡
Equal-cost multi-path (ECMP)

查看Cisco Router CPU 運作狀況

查看Router CPU 運作狀況 sh proc cpu

Hinet ADSL MRTG 報表呈現解讀

日流量:每小格為1小時;每大格為6小時
週流量:每小格為6小時;每大格為1日(號)
月流量:每小格為1日;每大格為1周
年流量:每大格為1月

DOS中的GREP

netstat -n -p TCP |find "30002"

執行批次檔時,依日期產生LOG檔

D:\appbak.bat >> d:\%date:~4,4%%date:~9,2%%date:~12,2%.log

其它連結:http://motoya363.wordpress.com/2007/03/09/

win2k 如何支援>137GB的硬碟

若在按裝SP4前,即進行Partition 的分割,則只能存取130G的空間,事後要調整,則需設定windwos registry

在「開始→執行」中按鍵輸入regedit,
在 HKEY_LOCAL_MACHIN\ESYSTEM\CurrentControlSet\Services\Atapi\Parameters下,
建立一個 DWORD值,名為EnableBigLba,數值填1,

參考資料:
http://blog.yam.com/invite19/article/2397659

網路流量監控 NetFlow

nProbe --> NetFlow --> NetFlow Analyzer

關鍵字
NetflowExporter
http://sunsite.cc.ncu.edu.tw/NetflowExporter/

ManageEngine Netflow Analyzer
http://www.manageengine.com/

Search Engine Optimization(SEO)

搜尋引擎優化(Search Engine Optimization)

SEO
網站排名服務是指網站經由SEO 優化, 進而符合搜尋引擎最佳化網站排序,達到網站排名效果。

@@ROWCOUNT

當查無資料時,視為一種錯誤,或是另一種意義時,可參考@@RWOCOUNT,傳回受到上一個陳述式影響的資料列數目,來採取其它行動。

select @retid = convert(int,state_class_a) from wid_state_def where wid_state_id = @stateid
if @@ROWCOUNT =0 set @retid = -1 else set @retid = isnull(@retid,0)

T-SQL % 取餘數,動態備份至不同磁碟

資料庫備份命令




CREATE PROCEDURE [dbo].[DatabaseBackup]
@dbname nvarchar(30),
@path varchar(100)
AS
BEGIN

declare @filename nvarchar(60)
declare @weekdayid varchar(1)
declare @db_cnt int

SELECT @weekdayid=DATEPART(weekday, GETDATE())

select @db_cnt=count(*) from master..sysdatabases where name=@dbname
if @db_cnt=0
begin
raiserror(N'資料庫名稱錯誤。', 16, 1)
goto TheEnd
end

if @weekdayid='1'
begin
select @filename=@path+'\'+@dbname+'_Sun.dat'
end

if @weekdayid='2'
begin
select @filename=@path+'\'+@dbname+'_Mon.dat'
end
.
.
.
if @weekdayid='7'
begin
select @filename=@path+'\'+@dbname+'__Sat.dat'
end

BACKUP DATABASE @dbname TO DISK = @filename WITH NOFORMAT, INIT, NAME = @filename, SKIP, NOUNLOAD, STATS = 10

declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=@dbname and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=@dbname )
if @backupSetId is null
begin
raiserror(N'確認失敗。找不到資料庫的備份資訊。', 16, 1)
goto TheEnd
end

RESTORE VERIFYONLY FROM DISK = @filename WITH FILE = @backupSetId, NOUNLOAD

TheEnd:

END

2009年4月24日 星期五

在VB中模擬超連結,以瀏覽器開啟網頁

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub LblLink_Click()
ShellExecute hWnd, "open", "http://bbs-mychat.com/index.php", vbNullString, vbNullString, conSwNormal
End Sub

Private Sub LblLink_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
LblLink.FontBold = True
LblLink.FontUnderline = True
LblLink.ForeColor = vbBlue
Me.MousePointer = 99
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
LblLink.FontBold = False
LblLink.FontUnderline = False
LblLink.ForeColor = vbBlack
Me.MousePointer = 0
End Sub

應用WINDOWS API時,要如何得知相關常數的定義?

請使用VB工具, API檢視員

http://bbs.zdnet.com.cn/thread-652693-1-1.html