开发者

How can i check if the table mysql.proc exists

I am working on a WPF application which installs if MySQL is installed, so before installation I want to check whether mysql.proc table exists or not. I googled about it and ended up with a query

select * from information_schema.Tables 
   where Table_schema = Schema() and Table_Name = 'mysql.proc'

This query returns an empty row.

I also tried simple select statement select * from mysql.proc, and this returned a table with the names of all the stored procedures, 开发者_JS百科but if this table didn't exists then it throws an exception in the c# code.

So is there any way that I can fire a query from c# and get a boolean value depending on whether mysql.proc table exists or not?


Try SHOW TABLES FROM mysql LIKE 'proc'. If there are no result rows, the table doesn't exist. If there is one row, the table exists. Note that this approach isn't portable across RDBMSs, though that doesn't seem to be a concern of yours.

As for your first query, SCHEMA() returns the default database, so if it's not "mysql", the query will fail. Likewise, data in the Table_Name column doesn't include the database name, so comparing to 'mysql.proc' will always fail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜