老是忘記,把它記錄下來
絕對值函數ABS
2009年7月28日 星期二
2009年7月27日 星期一
運用OUTLOOK 2000,實作行事曆維護及工作排程

主要觀念,是將工作項目以
- 優先性及建立時間2鍵值進行排序
- 優先性較高或建立時間較早的,排在前面,列入每天的執行項目
- 除了運用「優先性及建立時間2鍵值排序」外,
- 我再輔以「類別」及群組的機制,以及 "drag and drop" 的功能,
唯,欠缺子工作的機制,甚為可惜,對於同一項目所衍生的工作,變的不易追蹤及呈現。
另外,雖然OUTLOOK使我的待工作事項一目了然,但對於該作什麼,似乎沒什麼幫助, 因為,每天就竟該作什麼;每天就竟什麼優先,深深的被大環境左右著。
運用行事曆排程工作,只是時間管理中的一環,實驗證實,沒有全盤的運用,容易功虧一簣。不過,拿來匯整年度工作報告,或是週報告,都非常好用!
時間是珍貴的東西,對於系統管理者而言尤甚。沒有其他工作會把那麼多領域的事情,一次推給一個人作。使用者經常以他們的請求干擾你,讓你無法完成經理指派給你的長期專案;還有你的電腦就是不聽話,總是在最關鍵的時刻與你耍脾氣。儘管你精通職務上的技術,但是仍然發現必須在晚上和週末加班,只是為了達成一大堆要求。這只會隨著時間,增加自己的壓力。
本書討論的策略,不但幫你解決日常工作,還有能力處理無法避免所產生的突發狀況。作者將自己長期的職業生涯,諸如,支援桌面應用、伺服器管理、以及安全和軟體開發等等,詳實地舉例說明在本書中。這意味著,你將得到有實戰經驗的建言,而非象牙塔般,從未在混沌的網路工作過的陳腔濫調。
在其他技術上,你將學習如何:
- 管理干擾
- 消除時間的浪費
- 保持有效的行事曆
- 將經常發生的事情變成例行公事
- 專注在手邊的工作
- 以客戶預期的事排列優先順序
- 文件化和自動化處理以便快速執行
2009年7月22日 星期三
將定義變更儲存至含有大量資料的資料表,可能會需要相當長的時間。
重新定義資料表的schema時,在既有欄位中新增欄位(插入),可能涉及實體資料的排列順序,sql 2005 會出現如下提醒,而且真的做了好一陣子!而且,就其敘述,「將無法存取資料表中的資料」,茲事體大,在營運系統就沒採插入的方式新增欄位了!
但若是將新增的欄位,附加於既有欄位的最後面,則不會出現任何提醒,並且儲存異動,也一下就好了!
/*
2009年7月22日下午 12:26:53
使用者: sa
伺服器: 172.17.100.14
資料庫: xxxxdb
應用程式:
*/
'xxxx_tab' 資料表
- 將定義變更儲存至含有大量資料的資料表,可能會需要相當長的時間。儲存變更的期間,將無法存取資料表中的資料。
但若是將新增的欄位,附加於既有欄位的最後面,則不會出現任何提醒,並且儲存異動,也一下就好了!
2009年7月16日 星期四
2009年7月15日 星期三
Cursor Optimization Tips
本來以為 "INSENSITIVE" 、 "KEYSET"、 "STATIC" 選項,有助於系統效能,結果,發現..會錯意了..應避免使用之~
另外,CURSOR的選項,有些是相衝突的,該篇文章中,有用表格整理,一目了然!! "Cursor Options Compatibility"
參考資料:http://www.mssqlcity.com/
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 子句。
行 3: 只有 DECLARE CURSOR 才允許 FOR UPDATE 子句。
2009年7月13日 星期一
@@TRANCOUNT
例用 @@TRANCOUNT 來判斷預存程序目前已經開啟了幾個交易。 如果這個變數在預存程序中並沒有任何的變動,我們並不需要在預存程序中使用Commit 或 Rollback。
系統預存程序
系統預存程序會被儲存在系統資料庫(master 和 msdb)中,而且它們名稱是以sp_做為開頭。
這個字首並不只是個命名方式。它還告訴了伺服器這個預存程序被儲存在master資料庫中,而且使用者並不需要加上資料庫的名稱,就可以在所有的資料庫中使用這個預存程序!
這個字首並不只是個命名方式。它還告訴了伺服器這個預存程序被儲存在master資料庫中,而且使用者並不需要加上資料庫的名稱,就可以在所有的資料庫中使用這個預存程序!
2009年7月12日 星期日
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:
- SET is the ANSI standard for variable assignment, SELECT is not.
- SET can only assign one variable at a time, SELECT can make multiple assignments at once.
- 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)
- 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)
- 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]
http://ryanfarley.com/blog/archive/2004/03/01/390.aspx
2009年7月5日 星期日
除BUG的同時,也在寫BUG..
解決程式中的缺陷通常要比找出這些缺陷容易許多,但不要把這個皆段看得太過簡單。當程式發展循環來到這個階段時,如果產品的出貨日期已經逼近,你也許會被要求盡快修正。請不要急著修正:這通常會讓開發者在修正原有的錯誤時,又產生新錯誤。(戚戚..)這樣的錯誤通常並不是因為粗心或缺乏耐心所導致,而是來自於修正和出貨所帶來的巨大壓力。(戚戚..)
SQL Server 特別容易受到急於解決問題所產生的新問題所影響,因為預存程序只要一個動作就能夠被編譯和儲存。如果你試者在生產環境中解決缺陷,那麼整個生產環境可能會受到更嚴重的傷害。
雖然你還是能夠在生產環境進行修正,但是比較好的作法是往後退一步、花一點時間來瞭解問題、然後試著在生產環境外解決問題。
如果測試環並不存在,或是測試環境過於老舊,你也許想要節省一些時間而盡快的將問題修正。(戚戚..)然而,當你這麼做之前,你必須考慮如果在修正的過程中發生了其他的錯誤,系統資源將會有什麼樣的改變,以及如何還原。無論你做了什麼事,你都無法快速而輕易的將系統加以還原。
因此,很顯而易見的:你的確需要一個測試環境!
摘自:McGraw-Hill SQL SERVER 2000 預存程序 程式設計
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上的 程式碼嘍!
以前卻都沒用過,但它卻對我目前的現況非常有幫助,
我的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()看來可達到上述的效果
不過,實務上亦衍生出其它問題,當必要性的批次異動,卻也被此Trigger檢核擋了下來,目前正在尋求解決方案,看可否針對特定登入帳號,bypass 此檢合機制!有誰有其它的解決方案嗎?
suser_name()看來可達到上述的效果
2009年7月2日 星期四
2009年7月1日 星期三
資料庫索引,玩玩看
第一次採用MS SQL的自定函數-純量值函數
第一次採用MS SQL的自定函數,可將複雜且一再重複使用的東西模組化,增加程式的可讀性,並且統一維護商業邏輯,蠻好用的!
關鍵字:MSSQL2005, 純量值函數
關鍵字:MSSQL2005, 純量值函數
SQL #tmp_tab vs @var_tab
資料庫的暫存表格 #tmp_tab 和 變數型態的表格 @var_tab
應用上十分相像,就個人而言,比較習慣使用 #tmp_tab
另外,就上述兩項工具,根據心得,列出如下差異性!
應用上十分相像,就個人而言,比較習慣使用 #tmp_tab
另外,就上述兩項工具,根據心得,列出如下差異性!
- 兩者身命週期不同,#tmp_tab 依 connection;
@var_tab 依 batch - #tmp_tab 的 schema 可經由 select into 自動建立;
@var_tab 則需事先宣告
訂閱:
文章 (Atom)