create proc Proc_test_insert --If you want to modify this stored procedure, just change the Create to alter (@p_name nvarchar, @p_age int, @p_email varchar (+), @p_addres nvarchar, @p_remarks nvarchar [email protected] nvarchar out--to save the output error message, or success information Asbegin If @p_email is null or Len (@p_email) <=0 print ' email cannot be empty '; else if @p_addres is null or Len (@p_ad Dres) <=0 print ' address cannot be empty ' else begin INSERT INTO t_test values (@p_name, @p_age, @p_email, @p_addres, @p_remarks) print ' Insert succeeded ' endend exec proc_test_insert ' Wu Song ', "," [email protected] ', ', ' -- Insert will not succeed, error: "Address cannot be empty"
Or you can do it.
create proc Proc_test_insert --If you want to modify this stored procedure, just change the Create to alter (@p_name nvarchar, @p_age int, @p_email varchar (+), @p_addres nvarchar, @p_remarks nvarchar, @num nvarchar out--to save the output error message, or success information ) Asbeginset @num = "; If @p_email is null or Len (@p_email) <=0 Set @num = ' Email cannot be empty '; else if @p_addres is null or Len (@p_addres) <= 0 Set @num = ' address cannot be empty ' else begin INSERT INTO t_test values (@p_name, @p_age, @p_email, @p_addres, @p_ Remarks) Set @num = ' Insert succeeded ' endend declare @num nvarchar (); Exec proc_test_insert ' Lu Zhishen ', 45, ', ' Shandong province Jining Liangshan County ', ', @num out --insert will not succeed, will error: "Email cannot be empty" print @num