參考引用來源
--
SELECT r.scheduler_id as 排程器識別碼,
status as 要求的狀態,
r.session_id as SPID,
r.blocking_session_id as BlkBy,
substring(
ltrim(q.text),
r.statement_start_offset/2+1,
(CASE
WHEN r.statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(MAX), q.text)) * 2
ELSE r.statement_end_offset
END - r.statement_start_offset)/2)
AS [正在執行的 T-SQL 命令],
r.cpu_time as [CPU Time(ms)],
r.start_time as [開始時間],
r.total_elapsed_time as [執行總時間],
r.reads as [讀取數],
r.writes as [寫入數],
r.logical_reads as [邏輯讀取數],
-- q.text, /* 完整的 T-SQL 指令碼 */
d.name as [資料庫名稱]
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS q
LEFT JOIN sys.databases d ON (r.database_id=d.database_id)
WHERE r.session_id > 50 AND r.session_id <> @@SPID
ORDER BY r.total_elapsed_time desc
2014年3月12日 星期三
Alter Index All Tables
參考引用來源
--
SELECT
RowNum = ROW_NUMBER() OVER(ORDER BY t.TABLE_NAME)
,TableName = t.TABLE_SCHEMA + '.' + t.TABLE_NAME
,AlterMe = 'ALTER INDEX ALL ON [' + t.TABLE_SCHEMA + '].[' + t.TABLE_NAME + '] REBUILD;'
INTO #Reindex_Tables
FROM INFORMATION_SCHEMA.TABLES t
WHERE TABLE_TYPE = 'BASE TABLE'
DECLARE @Iter INT
DECLARE @MaxIndex INT
DECLARE @ExecMe VARCHAR(MAX)
SET @Iter = 1
SET @MaxIndex =
(
SELECT COUNT(1)
FROM #Reindex_Tables
)
WHILE @Iter < @MaxIndex
BEGIN
SET @ExecMe =
(
SELECT AlterMe
FROM #Reindex_Tables
WHERE RowNum = @Iter
)
EXEC (@ExecMe)
PRINT @ExecMe + ' Executed'
SET @Iter = @Iter + 1
END
參考引用來源2
select avg_fragmentation_in_percent, avg_fragment_size_in_pages, fragment_count, avg_page_space_used_in_percent
from sys.dm_db_index_physical_stats (DB_ID(), object_id('[dbo].[YourTableName]'), NULL, NULL, 'DETAILED')
-- Cursor going over each table and rebuilding every index of database.
DECLARE @TableName VARCHAR(255)
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 80
DECLARE TableCursor CURSOR FOR
SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@sql)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
--
SELECT
RowNum = ROW_NUMBER() OVER(ORDER BY t.TABLE_NAME)
,TableName = t.TABLE_SCHEMA + '.' + t.TABLE_NAME
,AlterMe = 'ALTER INDEX ALL ON [' + t.TABLE_SCHEMA + '].[' + t.TABLE_NAME + '] REBUILD;'
INTO #Reindex_Tables
FROM INFORMATION_SCHEMA.TABLES t
WHERE TABLE_TYPE = 'BASE TABLE'
DECLARE @Iter INT
DECLARE @MaxIndex INT
DECLARE @ExecMe VARCHAR(MAX)
SET @Iter = 1
SET @MaxIndex =
(
SELECT COUNT(1)
FROM #Reindex_Tables
)
WHILE @Iter < @MaxIndex
BEGIN
SET @ExecMe =
(
SELECT AlterMe
FROM #Reindex_Tables
WHERE RowNum = @Iter
)
EXEC (@ExecMe)
PRINT @ExecMe + ' Executed'
SET @Iter = @Iter + 1
END
參考引用來源2
select avg_fragmentation_in_percent, avg_fragment_size_in_pages, fragment_count, avg_page_space_used_in_percent
from sys.dm_db_index_physical_stats (DB_ID(), object_id('[dbo].[YourTableName]'), NULL, NULL, 'DETAILED')
-- Cursor going over each table and rebuilding every index of database.
DECLARE @TableName VARCHAR(255)
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 80
DECLARE TableCursor CURSOR FOR
SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'
EXEC (@sql)
FETCH NEXT FROM TableCursor INTO @TableName
END
CLOSE TableCursor
DEALLOCATE TableCursor
How to rebuild all the indexes of a database in SQL Server
參考引用來源
--
SQL Server 2000
=============
--Rebuild all indexes with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?')"
--Rebuild all indexes with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', [FILL_FACTOR_PERC])"
SQL Server 2005/2008
=================
You can either use the syntax provided above for SQL Server 2000 or:
--Rebuild all indexes online with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=ON)"
--Rebuild all indexes offline with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=OFF)"
--Rebuild all indexes online with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR=[FILL_FACTOR_PERC],ONLINE=ON)"
--Rebuild all indexes offline with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR=[FILL_FACTOR_PERC],ONLINE=OFF)"
--
SQL Server 2000
=============
--Rebuild all indexes with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?')"
--Rebuild all indexes with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', [FILL_FACTOR_PERC])"
SQL Server 2005/2008
=================
You can either use the syntax provided above for SQL Server 2000 or:
--Rebuild all indexes online with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=ON)"
--Rebuild all indexes offline with keeping the default fill factor for each index
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (ONLINE=OFF)"
--Rebuild all indexes online with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR=[FILL_FACTOR_PERC],ONLINE=ON)"
--Rebuild all indexes offline with specifying the fill factor
USE [DATABASE_NAME]
EXEC sp_MSforeachtable @command1="print '?'", @command2="ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR=[FILL_FACTOR_PERC],ONLINE=OFF)"
2014年3月11日 星期二
2014年3月10日 星期一
vbnet 如何設置datagridview的背景色為透明
參考引用來源:如何设置datagridview的背景色为透明
--
For i As Integer = 0 To dataGridView.Rows.Count - 1
dataGridView.Rows(i).DefaultCellStyle.BackColor = Colors.Transparent
Next
--
For i As Integer = 0 To dataGridView.Rows.Count - 1
dataGridView.Rows(i).DefaultCellStyle.BackColor = Colors.Transparent
Next
vb.net datagridview background image
參考引用來源:
--
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Namespace testproject
Public Class imagedgv
Inherits DataGridView
Private img As Image
Public Property Img() As Image
Get
Return img
End Get
Set
img = value
End Set
End Property
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
End Sub
Protected Overloads Overrides Sub OnSizeChanged(e As EventArgs)
MyBase.OnSizeChanged(e)
img = New Bitmap(img, Me.Width - Me.RowHeadersWidth, Me.Height - Me.ColumnHeadersHeight)
End Sub
Protected Overloads Overrides Sub PaintBackground(graphics As Graphics, clipBounds As Rectangle, gridBounds As Rectangle)
MyBase.PaintBackground(graphics, clipBounds, gridBounds)
graphics.DrawImage(img, New Point(Me.RowHeadersWidth, Me.ColumnHeadersHeight))
End Sub
Protected Overloads Overrides Sub OnCellPainting(e As DataGridViewCellPaintingEventArgs)
MyBase.OnCellPainting(e)
If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 Then
If Me(e.ColumnIndex, e.RowIndex).Style.BackColor <> Color.Red Then
Me(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Transparent
Else
Me(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Red
End If
End If
End Sub
Protected Overloads Overrides Sub OnMouseClick(e As MouseEventArgs)
Dim hti As DataGridView.HitTestInfo = Me.HitTest(e.X, e.Y)
If hti.Type = DataGridViewHitTestType.Cell Then
Dim c As DataGridViewCell = Me(hti.ColumnIndex, hti.RowIndex)
If c.Style.BackColor = Color.Red Then
c.Style.BackColor = Color.Transparent
c.Style.SelectionBackColor = Color.Transparent
Else
c.Style.BackColor = Color.Red
c.Style.SelectionBackColor = Color.Red
End If
End If
MyBase.OnMouseClick(e)
End Sub
End Class
End Namespace
--
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Namespace testproject
Public Class imagedgv
Inherits DataGridView
Private img As Image
Public Property Img() As Image
Get
Return img
End Get
Set
img = value
End Set
End Property
Public Sub New()
MyBase.New()
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
End Sub
Protected Overloads Overrides Sub OnSizeChanged(e As EventArgs)
MyBase.OnSizeChanged(e)
img = New Bitmap(img, Me.Width - Me.RowHeadersWidth, Me.Height - Me.ColumnHeadersHeight)
End Sub
Protected Overloads Overrides Sub PaintBackground(graphics As Graphics, clipBounds As Rectangle, gridBounds As Rectangle)
MyBase.PaintBackground(graphics, clipBounds, gridBounds)
graphics.DrawImage(img, New Point(Me.RowHeadersWidth, Me.ColumnHeadersHeight))
End Sub
Protected Overloads Overrides Sub OnCellPainting(e As DataGridViewCellPaintingEventArgs)
MyBase.OnCellPainting(e)
If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 Then
If Me(e.ColumnIndex, e.RowIndex).Style.BackColor <> Color.Red Then
Me(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Transparent
Else
Me(e.ColumnIndex, e.RowIndex).Style.BackColor = Color.Red
End If
End If
End Sub
Protected Overloads Overrides Sub OnMouseClick(e As MouseEventArgs)
Dim hti As DataGridView.HitTestInfo = Me.HitTest(e.X, e.Y)
If hti.Type = DataGridViewHitTestType.Cell Then
Dim c As DataGridViewCell = Me(hti.ColumnIndex, hti.RowIndex)
If c.Style.BackColor = Color.Red Then
c.Style.BackColor = Color.Transparent
c.Style.SelectionBackColor = Color.Transparent
Else
c.Style.BackColor = Color.Red
c.Style.SelectionBackColor = Color.Red
End If
End If
MyBase.OnMouseClick(e)
End Sub
End Class
End Namespace
訂閱:
文章 (Atom)




