Thursday, December 10, 2009

check is table exists in mysql 4.x

show tables like 'tbl name'

but you can not use this in t-sql openquery. in order to check the status from T-SQL openquery, you can use this statement instead.

show table status like 'tbl name'

sample code in T-SQL:
declare @rowCnt int
select @rowCnt = count(*) from OPENQUERY(PPC_DB_MYSQL,'show table status like "tbl name"')
if (@rowCnt=1)
BEGIN
END

you can also use exists function to see if there's record returned.

No comments: