標籤:進階查詢在資料庫中用得是最頻繁的,也是應用最廣泛的。Ø 基本常用查詢--selectselect * from student;--all 查詢所有select all sex from student;--distinct 過濾重複select distinct sex from student;--count 統計select count(*) from student;select count(sex) from student;select
標籤:轉:http://www.cnblogs.com/lyhabc/archive/2013/01/13/2858916.htmlSQL Server讀懂語句啟動並執行統計資訊 SET STATISTICS TIME IO PROFILE ON對於語句的運行,除了執行計畫本身,還有一些其他因素要考慮,例如語句的編譯時間、執行時間、做了多少次磁碟讀等。如果DBA能夠把問題語句單獨測試回合,可以在運行前開啟下面這三個開關,收集語句啟動並執行統計資訊。這些資訊對分析問題很有價值。1 SET
標籤: 讀取的記錄檔來自安裝目錄下:MSSQL\Log\ERRORLOG--This will hold the rowsCREATE TABLE #ErrorLog (LogDate datetime, ProcessInfo VarChar(10), ErrorMessage VarChar(Max))-- Dump the errorlog into the tableINSERT INTO #ErrorLogEXEC
標籤:本文介紹了SQL Server中Upsert的三種常見寫法以及他們的效能比較。SQL Server並不支援原生的Upsert語句,通常使用組合語句實現upsert功能。 假設有表table_A,各欄位如下所示:int型Id為主鍵。 方法1:先查詢,根據查詢結果判斷使用insert或者updateIF EXISTS (SELECT 1 FROM table_A WHERE Id = @Id) BEGIN UPDATE dbo.table_A
標籤:1 NOCOUNT選項當 SET NOCOUNT 為 ON 時,不返回計數。當 SET NOCOUNT 為 OFF 時,返回計數。eg:if object_id(N‘table_test‘,N‘U‘) IS not nulldrop table table_testgoCREATE TABLE table_test(id INT,name VARCHAR(50))goINSERT INTO table_test VALUES(1,‘xiaoming‘),(2,null)goSET
標籤:sql server一、列出資料庫1.列出所有庫use master;goselect name,dbid from master.dbo.sysdatabases2.只列出使用者庫use master;goselect name,dbid from master.dbo.sysdatabases where dbid>4;二、列出庫中的表1.只列出庫中的系統資料表;use