顯示具有 SQL 標籤的文章。 顯示所有文章
顯示具有 SQL 標籤的文章。 顯示所有文章

2009年9月10日 星期四

SQL 2005 Connection timeout 連線逾時處理

DBA’s Quick Guide to Timeouts

by Chris Kempster
The author of: SQL Server 2000 for the Oracle DBA
Click here for more information, sample chapters, or to purchase this e-book.
The application development DBA needs a good understanding of the overarching application architecture and subsequent technologies (COM+, MSMQ, IIS, ASP etc) to more proactively debug and track down database performance problems. A good place to start is common timeout error. This article will provide a brief overview of where to look and how to set the values.

ADO

Within ADO, the developer can set:

connection timeout (default 15 seconds)
if the connection cannot be established within the timeframe specified
command timeout (default 30 seconds)
cancellation of the executing command for the connection if it does not respond within the specified time.

These properties also support a value of zero, representing an indefinite wait.

Here is some example code:

Dim MyConnection as ADODB.Connection

Set MyConnection = New ADODB.Connection

MyConnection.ConnectionTimeout = 30

MyConnection.Open

- and -

Set MyConnection = New ADODB.Connection

<>

MyConnection.Open strMyConn


Set myCommand = New ADODB.Command

Set myCommand.ActiveConnection = MyConnection

myCommand.CommandTimeout = 15

Take care with command timeouts are described by Microsoft:

http://support.microsoft.com/default.aspx?scid=KB;en-us;q188858

文件原文 http://vyaskn.tripod.com/watch_your_timeouts.htm

2009年6月2日 星期二

SQL SERVER ODBC

SQL SERVER ODBC 有兩種, 一種是SQL SERVER DRIVER, 另一種是SQL Native Client.
如果SQL SERVER 是SQL 2005以後的(含SQL 2005), 那要用SQL Native Client,
SQL 2003以前的(), 那用SQL SERVER DRIVER就可以了.

2009年6月1日 星期一

Windows 定序排序樣式

二進位 (_BIN)1 依據對每一個字元定義的位元模式來排序和比較 SQL Server 資料表中的資料。二進位排序順序有區分大小寫和區分腔調字。二進位也是最快的排序順序。如需詳細資訊,請參閱<使用二進位定序>。

如果未選取這個選項,SQL Server 會遵照相關聯語言或字母之字典所定義的排序和比較規則。

二進位碼指標 (_BIN2)1 依據 Unicode 資料的 Unicode 字碼指標來排序和比較 SQL Server 資料表中的資料。對於非 Unicode 資料,二進位碼指標將使用與二進位排序相同的比較。

使用二進位碼指標排序順序的好處,就是在比較已排序 SQL Server 資料之應用程式中的資料不需要重新排序。因此,二進位碼指標排序順序可簡化應用程式的開發並提升效能。如需詳細資訊,請參閱<使用二進位定序>。

區分大小寫 (_CS) 區分大寫和小寫字母。如果選取,排序時小寫字母將先於其大寫字母。

如果未選取這個選項,在排序用途上,SQL Server 會將字母大寫和小寫的版本視為相同。

區分腔調字 (_AS) 區分有腔調和無腔調字元。例如,'a' 不等於 'ấ'。

如果未選取這個選項,在排序用途上,SQL Server 會將有腔調和無腔調字母的版本視為相同。

區分假名 (_KS) 區分兩種類型的日文假名字元:平假名和片假名。

如果未選取這個選項,則在排序用途上,SQL Server 會將平假名和片假名字元視為相同。

區分全半形 (_WS) 區分單一位元組字元和以雙位元組字元表示的相同字元。

如果未選取這個選項,在排序用途上,SQL Server 會將單一位元組和相同字元的雙位元組表示法視為相同。


Windows 定序後置詞 排序順序描述
_BIN1 二進位排序。

_BIN21 二進位碼指標排序順序,SQL Server 2005 的新增功能。

_CI_AI 不區分大小寫、不區分腔調字、不區分假名、不區分全半形。

_CI_AI_KS 不區分大小寫、不區分腔調字、區分假名、不區分全半形

_CI_AI_KS_WS 不區分大小寫、不區分腔調字、區分假名、區分全半形

_CI_AI_WS 不區分大小寫、不區分腔調字、不區分假名、區分全半形

_CI_AS 不區分大小寫、區分腔調字、不區分假名、不區分全半形

_CI_AS_KS 不區分大小寫、區分腔調字、區分假名、不區分全半形

_CI_AS_KS_WS 不區分大小寫、區分腔調字、區分假名、區分全半形

_CI_AS_WS 不區分大小寫、區分腔調字、不區分假名、區分全半形

_CS_AI 區分大小寫、不區分腔調字、不區分假名、不區分全半形

_CS_AI_KS 區分大小寫、不區分腔調字、區分假名、不區分全半形

_CS_AI_KS_WS 區分大小寫、不區分腔調字、區分假名、區分全半形

_CS_AI_WS 區分大小寫、不區分腔調字、不區分假名、區分全半形

_CS_AS 區分大小寫、區分腔調字、不區分假名、不區分全半形

_CS_AS_KS 區分大小寫、區分腔調字、區分假名、不區分全半形

_CS_AS_KS_WS 區分大小寫、區分腔調字、區分假名、區分全半形

_CS_AS_WS 區分大小寫、區分腔調字、不區分假名、區分全半形

文章來源:http://technet.microsoft.com/zh-tw/library/ms143515(SQL.90).aspx

2009年4月15日 星期三

關於COLLATE Chinese_Taiwan_Stroke_CS_AS 用法

安裝的SQL Server是不區分大小寫的,
若要使用區分大小寫的SQL, 在Where後加上 COLLATE Chinese_Taiwan_Stroke_CS_AS

select * from Templatemaster
where TemplateID = 'PCA' COLLATE Chinese_Taiwan_Stroke_CS_AS

它另一個用途是如果要串兩個SQL資料庫, 也必須用到Chinese_Taiwan_Stroke_CS_AS

2008年11月14日 星期五

SQL資料庫還原令

如果SQL資料庫備份檔要還原的檔案位置, 和原備份位置不相同,
就要修改指令檔備份

指令範例:

RESTORE DATABASE [DSCSYS]

FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\DSCSYS_backup_200811140000.bak\DSCSYS_backup_200811140000.bak'
WITH MOVE 'DSCSYS_data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\DSCSYS.mdf',
MOVE 'DSCSYS_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\DSCSYS.log',
REPLACE;
GO

2008年10月5日 星期日

清除SQL 2005 資料庫 LOG

2007年11月19日 星期一

在ASP中使用SQL LOCK TABLE範例

Set XACT_ABORT ON
Begin tran
Select @SNO = strNum from test With (XLOCK) Where strYMD = @SToday
Update test set strNum = strNum + 1 where strYMD = @SToday
if @@Error <> 0
Rollback Tran
else
Commit Tran
Set XACT_ABORT OFF

2007年9月11日 星期二

兩台SQL資料庫同步Table的問題

1. 請先執行以下命令,並記得告訴我其回傳值
select @@ServerName

2. EXEC sp_dropserver '您的伺服器名稱', 'droplogins'
若是沒辦法刪除時,請再執行
EXEC sp_dropremotelogin '您的伺服器名稱'

3. EXEC sp_addserver '您的伺服器名稱', 'local'
您必須要重新啟動SQL Server後才會生效。

4. 再度執行以下命令,並記得告訴我其回傳值
select @@ServerName

5. 執行
EXEC SP_ADDDISTRIBUTOR @distributor='您的伺服器名稱'

6. 最後,再重新建立 Replication 。

參考資訊:
HOW TO:在不受信任網域或網際網路中執行 SQL Server 的電腦之間設定複寫
http://support.microsoft.com/?id=321822
原文出自 微軟技術社群討論區
http://forums.microsoft.com/MSDN-CHT/ShowPost.aspx?PostID=594676&SiteID=14

2007年9月10日 星期一

在SQL中隨機取得資料

MYSQL用法:
SELECT id FROM table_name order by rand() limit 10

MSSQL用法:
select top 10 * from table_name order by newid()

Oracle 用法
select * from table_name where rownum <=10 order by rowid()

修改SQL SERVER 中物件OWNER 語法

EXEC sp_changeobjectowner '[_alan.chang].LuckyVote_Member', 'dbo'