Create function fun_getPY ( @str nvarchar(4000) )returns nvarchar(4000)asbegin declare @word nchar(1),@PY nvarchar(4000) set @PY='' while len(@str)>0 begin set @word=left(@str,1) --如果非漢字字元,返回原字元 set @PY=@PY+(case when
為什麼使用事務 當對多個表進行更新的時候,某條執行失敗。為了保持資料的完整性,需要使用交易回復。 顯示設定事務 begin try begin transaction insert into shiwu (asd) values ('aasdasda'); commit transaction end try begin catch select ERROR_NUMBER() as errornumber rollback transaction
Sql Server資料庫中表等對象都儲存在sysobjects資料表中,暫存資料表被儲存於tempdb資料庫中1.判斷普通表是否存在,可以使用object_id函數,它可以根據對象名稱返回對象的idif (select object_id('TableName')) is not null select 'true'else select 'false'或者if exists(select [id] from [sysobjects] where [name]='TableName')
取表資訊 select sysobjects.name,sys.extended_properties.value from sysobjects left join sys.extended_properties on sysobjects.id=sys.extended_properties.major_id where type= 'U ' and sys.extended_properties.minor_id='0' order by name 取欄位資訊 sele
減少資料庫死結!Here are some tips on how to avoid deadlocking on your SQL Server:Ensure the database design is properly normalized. Have the application access server objects in the same order each time. During transactions, don't allow any user input.
SQL Server 中四種匹配符的含義 % 代表零個或者多個任一字元 _ 代表一個任一字元 [] 指定範圍內的任意單個字元 [^] 不在指定範圍內的任意單個字元 帶有匹配符的字串必須使用引號引起來,例如下面的樣本: LIKE 'BR%'返回以“BR”開始的任一字元串。 LIKE 'Br%'返回以“Br”開始的任一字元中。 LIKE '%een'返回以“een”結束的任一字元串。 LIKE
最近在開發項目的過程中遇到這麼一個問題,就是在插入一條記錄的後立即擷取其在資料庫中自增的ID,以便處理相關聯的資料,怎麼做?在sql server 2000中可以這樣做,有幾種方式。詳細請看下面的講解與對比。一、要擷取此ID,最簡單的方法就是:(以下舉一簡單實用的例子)--建立資料庫和表create database MyDataBaseuse MyDataBasecreate table mytable(id int identity(1,1),name