且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查是否在mysql表中插入了一行

更新时间:2023-11-30 21:54:34

两种方式..



1.你可以拥有存储过程中的输出变量表示插入成功或失败。



如果输出变量值成功则插入记录。否则没有插入。



2.您可以使用触发器。当行插入或删除或更新时,此方法有效。



欲了解更多信息,请参阅以下链接..

http://dev.mysql.com/doc/refman/5.0/en/create-trigger。 html [ ^ ]

http://dev.mysql.com/doc /refman/5.0/en/triggers.html [ ^ ]

http:// www .sitepoint.com / how-to-create-mysql-triggers / [ ^ ]
Two ways..

1. You can have Output variable in your stored proceedure indicating successful or failure of inserting.

if output variable value successful then the record get inserted. else not inserted.

2. You can use trigger''s. This works when row inserted or deleted or updated.

For more see below link..
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html[^]
http://dev.mysql.com/doc/refman/5.0/en/triggers.html[^]
http://www.sitepoint.com/how-to-create-mysql-triggers/[^]


这是一个例子..



Here is one example..

ALTER PROCEDURE dbo.postcomments_sp_global
	@aaa,
	@output varchar(50) output // output variable
	AS
	begin try
	insert into tablename(col1) 
values(@aaa) 
set @output='Record inserted successfully... Thank you..'
print @output
end try
begin catch
set @output=(select error_message() as err)//error message
end catch