CREATE TABLE dbo.emp ( empno int NOT NULL) go create procedure dbo.p_emp_insert (@empno int) as begin -- CODE...
THAT MAY FAIL begin try insert into emp (empno) values (@empno) end try -- EXECUTED IF THERE IS A FAILURE begin catch SELECT ERROR_NUMBER()as ERROR_NUMBER, ERROR_SEVERITY()as ERROR_SEVERITY, ERROR_STATE()as ERROR_STATE, ERROR_MESSAGE()as ERROR_MESSAGE end catch end -- First exec should work with a valid empno … exec dbo.p_emp_insert 1003 -- This should fail because the column does not allow NULLs -- We should see the error information returned exec p_emp_insert NULL
Dig Deeper on SQL Server Stored Procedures
Related Q&A from Joe Toscano
Migrate DTS packages to SQL Server Integration Services with Migration Wizard and deploy SSIS packages in SQL 2005. Learn how to access DTS Designer ... Continue Reading
Is there a query to search text in a SQL Server DTS package? SQL Server expert Joe Toscano explains which database objects can be viewed. Continue Reading
Getting an error when importing data from an Excel spreadsheet to SSIS in SQL Server 2005? Try lining up data types in Excel and SSIS so they match. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.