Hi @Sudip Bhatt ,
Quote code from this doc. : sql-server-error-logging-and-reporting-within-a-stored-procedure
CREATE TABLE [dbo].[ErrorLogTable]
(
[ErrorID] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[ErrorNumber] [nvarchar](50) NOT NULL,
[ErrorDescription] [nvarchar](4000) NULL,
[ErrorProcedure] [nvarchar](100) NULL,
[ErrorState] [int] NULL,
[ErrorSeverity] [int] NULL,
[ErrorLine] [int] NULL,
[ErrorTime] [datetime] NULL
);
CREATE PROCEDURE [dbo].[ErrorLogInsert]
AS
INSERT INTO [ErrorLogTable]
(
ErrorNumber
,ErrorDescription
,ErrorProcedure
,ErrorState
,ErrorSeverity
,ErrorLine
,ErrorTime
)
VALUES
(
ERROR_NUMBER()
,ERROR_MESSAGE()
,ERROR_PROCEDURE()
,ERROR_STATE()
,ERROR_SEVERITY()
,ERROR_LINE()
,GETDATE()
);
If you want to read all the errors and warings, you can follow scrips from this one: read-all-errors-and-warnings-in-the-sql-server-error-log-for-all-versions
More information: sql-server-error-logging-from-a-stored-procedure ,logging-sql-server-database-errors, simple-way-to-find-errors-in-sql-server-error-log
BR,
Mia
If the answer is helpful, please click "Accept Answer" and upvote it.