设为首页 加入收藏

TOP

SQL数据库备份解决方案 完整版(二)
2014-11-24 00:40:56 来源: 作者: 【 】 浏览:33
Tags:SQL 数据库 备份 解决方案 整版
quotename(i.name)

,IxPKFlag=i.is_primary_key

,IxType=casewhen i.is_primary_key=1then 'PRIMARY KEY 'when i.is_unique=1then 'UNIQUE ' else '' end

+lower(type_desc)

,IxDef='('+IxColList+')'

+coalesce(' INCLUDE ('+IxInclList+')','')

,IxOpts=IxOptList

from sys.indexesi

left joinsys.statss ON i.index_id=s.stats_idand i.[object_id]=s.[object_id]

cross apply(

select stuff((selectcase when i.is_padded=1then ', PAD_INDEX=ON'else '' end

+casewheni.fill_factor<>0then ', FILLFACTOR='+cast(i.fill_factoras varchar(10))else '' end

+casewheni.ignore_dup_key=1then ', IGNORE_DUP_KEY=ON'else'' end

+casewhens.no_recompute=1then ',STATISTICS_RECOMPUTE=ON'else '' end

+casewheni.allow_row_locks=0then ', ALLOW_ROW_LOCKS=OFF'else'' end

+casewheni.allow_page_locks=0then ', ALLOW_PAGE_LOCKS=OFF'else'' end)

,1,2,''))F_IxOpts(IxOptList)

cross apply(

select stuff((select','+quotename(c.name)

+case

when ic.is_descending_key=1AND i.type<>3

then ' DESC'

WHEN ic.is_descending_key=0AND i.type<>3

THEN ' ASC'

ELSE ''

end

fromsys.index_columnsic

joinsys.columnsc ON ic.[object_id]=c.[object_id]

andic.column_id=c.column_id

whereic.[object_id]=i.[object_id]

andic.index_id=i.index_id

andic.is_included_column=0

orderbyic.key_ordinal

FORxmlpath(''),type).value('.','nvarchar(max)')

,1,1,''))F_IxCols(IxColList)

cross apply(

select stuff((select','+quotename(c.name)

fromsys.index_columnsic

joinsys.columnsc ON ic.[object_id]=c.[object_id]

andic.column_id=c.column_id

whereic.[object_id]=i.[object_id]

andic.index_id=i.index_id

andic.is_included_column=1

orderbyic.key_ordinal

FORxmlpath(''),type).value('.','nvarchar(max)')

,1,1,''))F_IxIncl(IxInclList)

where i.type_desc<>'HEAP'

)

,FKDefsas

(

select TableObj=f.parent_object_id

,FKName=quotename(f.name)

,FKRef=quotename(object_schema_name(f.referenced_object_id))+'.'

+quotename(object_name(f.referenced_object_id))

,FKColList=ParentColList

,FKRefList=RefColList

,FKDelOpt=casef.delete_referential_action

when1 then 'CASCADE'

when2 then 'SET NULL'

when3 then 'SET DEFAULT'

end

,FKUpdOpt=casef.update_referential_action

when1 then 'CASCADE'

when2 then 'SET NULL'

when3 then 'SET DEFAULT'

end

,FKNoRepl=f.is_not_for_replication

from sys.foreign_keysf

cross apply(

select stuff((select','+quotename(c.name)

fromsys.foreign_key_columnsk

joinsys.columnsc ON k.parent_object_id=c.[object_id]

and k.parent_column_id=c.column_id

wherek.constraint_object_id=f.[object_id]

orderbyconstraint_column_id

FORxmlpath(''),type).value('.','nvarchar(max)')

,1,1,''))F_Parent(ParentColList)

cross apply(

select stuff((select','+quotename(c.name)

fromsys.foreign_key_columnsk

joinsys.columnsc ON k.referenced_object_id=c.[object_id]

and k.referenced_column_id=c.column_id

wherek.constraint_object_id=f.[object_id]

orderbyconstraint_column_id

FORxmlpath(''),type).value('.','nvarchar(max)')

,1,1,''))F_Ref(RefColList)

)

select TableName

,[definition]

from sys.tablest

cross apply(

select TableName=quotename(object_schema_name(t.[object_id]))+'.'

+quotename(object_name(t.[object_id])))F_Name

cross apply(

select stuff((select@crlf+' ,'+ColumnDef

fromColumnDefs

whereTableObj=t.[object_id]

orderby

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇面试不是意味着给解决方案,有时.. 下一篇ORA-28002:thepasswordwillexpire..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: