#contents

*これだけはやっておけ [#z6b3ddbf]
+MAX DOPの設定
 1/4 or 1/2×物理CPU数(物理コア数)
 ※HTとかの論理数ではない
+tempdbのデータファイルの分割
 CPUのコア数と同じにする
+SQL Serverアカウントにメモリ内のページロックの権限を付与


*オブジェクト(テーブルとか)の所有者変更 [#md420c10]
 sp_changeobjectowner OBJECT_NAME, OWNER_NAME

*欠落インデックスのレポート [#nea276a5]
-これで、ある程度不足しているインデックスがわかる
 SELECT 
 migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) cost_impact
 ,migs.avg_total_user_cost
 ,migs.avg_user_impact
 ,migs.user_seeks
 ,migs.user_scans
 ,mid.statement
 ,mid.equality_columns
 ,mid.inequality_columns
 ,mid.included_columns
 FROM sys.dm_db_missing_index_group_stats AS migs
 INNER JOIN sys.dm_db_missing_index_groups AS mig
     ON (migs.group_handle = mig.index_group_handle)
 INNER JOIN sys.dm_db_missing_index_details AS mid
     ON (mig.index_handle = mid.index_handle)
 WHERE migs.group_handle in
 (
 SELECT TOP 50 group_handle
 FROM sys.dm_db_missing_index_group_stats
 ORDER BY avg_total_user_cost * avg_user_impact * (user_seeks + user_scans) DESC
 )
 ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC


*インデックス一覧 [#y1cc40dc]
 select
 i.name  as indes_name
 , ob.name as table_name
 , col.name as column_name
 , ix.id
 , ix.indid
 , ix.keyno
 from
 sysindexkeys ix
 , sysobjects ob
 , syscolumns col
 , sysindexes i
 where
 ix.id = ob.id
 and ix.id = col.id
 and ix.colid = col.colid
 and i.id = ix.id
 and i.indid = ix.indid
 and ob.xtype in ('U','PK')
 order by ob.name,ob.xtype,i.name,ix.id,ix.indid,ix.keyno

*テーブル使用容量 [#qfd205a4]
 BEGIN
 
   DECLARE @tablename VARCHAR(256)
   declare @id int
         declare @rows int, @datasizeused int, @indexsizeused int, @pagesize int
 
   DECLARE tablelist CURSOR FOR
         SELECT Name FROM Sys.Tables ORDER BY Name
 
   SET NOCOUNT ON
 
         CREATE TABLE #table_size (
                  TABLE_NAME VARCHAR(256)
                 ,ROWS INT
                 ,DATA_SIZE INT
                 ,INDEX_SIZE INT
         )
 
         select @pagesize = v.low / 1024 from master..spt_values v where v.number=1 and v.type=N'E'
 
   OPEN tablelist
 
   FETCH NEXT FROM tablelist INTO @tablename
   WHILE @@FETCH_STATUS = 0
   BEGIN
         select @id = id from dbo.sysobjects where id = object_id(@tablename) and (OBJECTPROPERTY(id, N'IsTable') = 1)
 
         /* rows */
         SELECT @rows = convert(int, rowcnt)
                 FROM dbo.sysindexes
                 WHERE indid < 2 and id = @id
 
         /* data */
         SELECT @datasizeused =
                 SUM(CASE WHEN a.type <> 1 THEN a.used_pages
                                 WHEN p.index_id < 2 THEN a.data_pages
                                 ELSE 0
                         END)
         FROM sys.indexes as i
         JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
         JOIN sys.allocation_units as a ON a.container_id = p.partition_id
         where i.object_id = @id
 
         /* index */
         SELECT @indexsizeused =
                 sum(isnull(sidx.used,0)-isnull(sidx.dpages,0))
                 FROM dbo.sysindexes sidx
                 WHERE sidx.indid < 2 and sidx.id = @id
 
 
         insert into #table_size
         values( @tablename, @rows, @datasizeused* @pagesize, @indexsizeused*@pagesize)
 
         FETCH NEXT FROM tablelist INTO @tablename
   END
 
         SELECT * FROM #table_size
 drop table #table_size
   --(5)終了処理
   DEALLOCATE tablelist
 
 END

*Agent XPs の設定 [#n8c06550]
-SQL Server エージェントの拡張ストアド プロシージャを使用できるようにする
 sp_configure 'show advanced options', 1;
 GO
 RECONFIGURE;
 GO
 sp_configure 'Agent XPs', 1;
 GO
 RECONFIGURE
 GO

*タブ区切りファイルのインポート [#o92b1052]
 bcp database_name.dbo.table_name in filename.txt -Uuser -Ppass -Sserver -c




~
~
CENTER:&amazon(zaurus,key,SQL SQLServer SQLサーバ Windows, books);


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS