Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Cara mengambil prosedur tersimpan, fungsi, tabel yang dijatuhkan di SQL Server 2008

Saya mendapat Solusi untuk pertanyaan saya. Pertama Perlu membuat prosedur

CREATE PROCEDURE [dbo].[sp_Recover_Dropped_Objects]
    @Database_Name NVARCHAR(MAX),
    @Date_From DATETIME,
    @Date_To DATETIME
AS

DECLARE @Compatibility_Level INT

SELECT @Compatibility_Level=dtb.compatibility_level
FROM master.sys.databases AS dtb WHERE [email protected]_Name

IF ISNULL(@Compatibility_Level,0)<=80
BEGIN
    RAISERROR('The compatibility level should be equal to or greater SQL SERVER 2005 (90)',16,1)
    RETURN
END

Select [Database Name],Convert(varchar(Max),Substring([RowLog Contents 0],33,LEN([RowLog Contents 0]))) as [Script]
from fn_dblog(NULL,NULL)
Where [Operation]='LOP_DELETE_ROWS' And [Context]='LCX_MARK_AS_GHOST'
And [AllocUnitName]='sys.sysobjvalues.clst'
AND [TRANSACTION ID] IN (SELECT DISTINCT [TRANSACTION ID] FROM    sys.fn_dblog(NULL, NULL)
WHERE Context IN ('LCX_NULL') AND Operation in ('LOP_BEGIN_XACT') 
And [Transaction Name]='DROPOBJ'
And  CONVERT(NVARCHAR(11),[Begin Time]) BETWEEN @Date_From AND @Date_To)
And Substring([RowLog Contents 0],33,LEN([RowLog Contents 0]))<>0

Jalankan prosedur seperti di bawah ini

EXEC sp_Recover_Dropped_Objects 'Sample_Training','2015/12/24','2015/01/07'



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Cara Memperbaiki "Skema partisi '...' tidak memiliki filegroup yang digunakan berikutnya" di SQL Server

  2. Perbarui beberapa kolom dalam SQL

  3. DESC dan ASC sebagai parameter dalam prosedur tersimpan

  4. UNION ALL vs kondisi ATAU dalam permintaan server sql

  5. Bagaimana TRY_CAST() Bekerja di SQL Server