Set nocount on; --/* -- = ==== -- job -- server/jobserver/job [@ name = '{1}'] selecturn = n' server/jobserver/job [@ name = '+ quotename (name, n''') + N'] ', script_file = nullfrom MSDB. DBO. sysjobs job with (nolock) where job. category_id in (-- not include replication jobselect cat. category_idfrom MSDB. DBO. syscategories cat with (nolock) where Cat. category_class = 1and cat. name not in (N 'Log shipping') and CAT. name Not Like N 'repl-% ') and enabled = 1 -- not include disable job; -- ===================================================== = * // * -- ========================================== ====== -- schema -- server/database [@ name = '{0}']/Schema [@ name = '{1}'] selecturn = n' server' + N'/database [@ name = '+ quotename (db_name (), N ''') + N'] '+ N'/Schema [@ name =' + quotename (obj. name, n''') + N'] ', script_file = nullfrom sys. schemas OBJ with (nolock) Inner join sys. database_principals DP with (nolock) on DP. principal_id = obj. principal_idwhere DP. type in ('s', 'U', 'G', 'C', 'k') and obj. name not in (N 'dbo', N 'sys ', N 'guest', N 'information _ scheme') and obj. name Not Like n' % mark % Delete % 'and not (obj. name = DP. nameand obj. name like n' % dbo '); -- ===================================================== = * // * -- ========================================== ====== -- tables -- server/database [@ name = '{0}']/table [@ name = '{1}' and @ schema = '{2} '] selecturn = n 'server' + N'/database [@ name =' + quotename (db_name (), N ''') + N'] '+ N'/table [@ name =' + quotename (obj. name, n''') + N' and @ schema = '+ quotename (Sch. name, n''') + N'] ', script_file = Sch. name + N '. '+ obj. namefrom sys. tables OBJ with (nolock) Inner join sys. schemas Sch with (nolock) on Sch. schema_id = obj. schema_idwhere obj. is_ms_shipped = 0and obj. name Not Like n' % mark % Delete % '-- and Sch. name = n 'dbo '; -- ===================================================== = * // * -- ========================================== ====== -- Views -- server/database [@ name = '{0}']/view [@ name = '{1}' and @ schema = '{2} '] selecturn = n 'server' + N'/database [@ name =' + quotename (db_name (), N ''') + N'] '+ N'/view [@ name =' + quotename (obj. name, n''') + N' and @ schema = '+ quotename (Sch. name, n''') + N'] ', script_file = Sch. name + N '. '+ obj. namefrom sys. views OBJ with (nolock) Inner join sys. schemas Sch with (nolock) on Sch. schema_id = obj. schema_idwhere obj. is_ms_shipped = 0and obj. name Not Like n' % mark % Delete % '-- and Sch. name = n 'dbo '; -- ===================================================== = * // * -- ========================================== ====== -- functions -- server/database [@ name = '{0}']/userdefinedfunction [@ name = '{1}' and @ schema = '{2} '] selecturn = n 'server' + N'/database [@ name =' + quotename (db_name (), N ''') + N'] '+ N'/userdefinedfunction [@ name =' + quotename (obj. name, n''') + N' and @ schema = '+ quotename (Sch. name, n''') + N'] ', script_file = Sch. name + N '. '+ obj. namefrom sys. objects OBJ with (nolock) Inner join sys. schemas Sch with (nolock) on Sch. schema_id = obj. schema_idwhere obj. type in ('tf', 'fn ', 'if', 'fs', 'ft', 'af') and obj. is_ms_shipped = 0and obj. name Not Like n' % mark % Delete % '-- and Sch. name = n 'dbo '; -- ===================================================== = * // * -- ========================================== ====== -- procedures -- server/database [@ name = '{0}']/storedprocedure [@ name = '{1}' and @ schema = '{2} '] selecturn = n 'server' + N'/database [@ name =' + quotename (db_name (), N ''') + N'] '+ N'/storedprocedure [@ name =' + quotename (obj. name, n''') + N' and @ schema = '+ quotename (Sch. name, n''') + N'] ', script_file = Sch. name + N '. '+ obj. namefrom sys. procedures OBJ with (nolock) Inner join sys. schemas Sch with (nolock) on Sch. schema_id = obj. schema_idwhere obj. is_ms_shipped = 0and obj. name Not Like n' % mark % Delete % '-- and Sch. name = n 'dbo '; -- ===================================================== = */