检查MySQL表是否存在的不同方法?
让我们看看一些检查表是否存在于MySQL中的方法。
使用SHOW
SHOW命令显示所有表。
SHOW tables;
这是输出。
+--------------------------+ | Tables_in_business | +--------------------------+ | addcheckconstraintdemo | | addcolumntable | | addconstraintdemo | | alphademo | | autoincrement | | autoincrementtable | | backticksymbol | | bookindexes | | chardemo | | checkdemo | | clonestudent | | columnexistdemo | | columnvaluenulldemo | | commaseperatedemo | | dateadddemo | | deletedemo | | deleterecord | | demo | | demo1 | | demoascii | | demoauto | | demobcrypt | | demoemptyandnull | | demoint | | demoonreplace | | demoschema | | demowhere | | distinctdemo | | duplicatebookindexes | | duplicatefound | | employeetable | | escapedeom | | existsrowdemo | | findandreplacedemo | | firsttable | | foreigntable | | foreigntabledemo | | functiontriggersdemo | | groupdemo | | groupdemo1 | | ifelsedemo | | imagedemo | | incasesensdemo | | indexingdemo | | int1demo | | intdemo | | latandlangdemo | | limitoffsetdemo | | milliseconddemo | | modifycolumnnamedemo | | modifydatatype | | moneydemo | | moviecollection | | multipleindexdemo | | multiplerecordwithvalues | | mytable | | mytable1 | | nextpreviousdemo | | nonasciidemo | | nthrecorddemo | | nulldemo | | nullwithselect | | numbercolumndemo | | ondemo | | pasthistory | | presenthistory | | primarytable | | primarytable1 | | primarytabledemo | | qutesdemo | | rowcountdemo | | rownumberdemo | | rowstranspose | | rowstransposedemo | | secondtable | | sequencedemo | | smallintdemo | | sortingvarchardemo | | spacecolumn | | student | | tbldemotrail | | tblf | | tblfirst | | tblfunctiontrigger | | tblifdemo | | tblp | | tblselectdemo | | tblstudent | | tbluni | | tblupdatelimit | | textdemo | | texturl | | timestampdemo | | trailingandleadingdemo | | transcationdemo | | triggedemo | | trigger1 | | trigger2demo | | unsigneddemo | | updtable | | usernameandpassworddemo | | varchardemo | | varchardemo1 | | varchardemo2 | | varcharurl | | whereconditon | | xmldemo | +--------------------------+ 107 rows in set (0.15 sec)
使用LIKE显示单个表格
这是语法。
SHOW TABLES LIKE 'yourTableName';
现在让我们在以下查询中实现以上语法。
mysql> SHOW TABLES LIKE 'tblstudent';
这是输出。
+---------------------------------+ | Tables_in_business (tblstudent) | +---------------------------------+ | tblstudent | +---------------------------------+ 1 row in set (0.00 sec)