Checking if MySQL Tables Exist and if not create them
What would be the best way to check if tables exist in a MySQL DB? I was looking at a few code examples and have seen it done a couple of ways.
What I am trying to do is create tables like tag_tagnamehere so each tag has their own table with a link to the post/page ID.
So what I'm thinking is when people inset a list of TAGS I would loop through them and if the table is not found, 开发者_如何学编程create it and make and entry to that post/page ID.
CREATE TABLE IF NOT EXISTS
Maybe I didn't understand your design/table structure, although each tag shouldn't reside in its own table. You should have a table of tags, and a normalised scenario where other tables (if need be) define other tag attributes
Create table has that built in.
Create table Foo if not exists
But you probably shouldn't do this. Note how its done here with a PostTag table
CREATE TABLE IF NOT EXISTS <table_name>...
How about directly from a MySQL Query?
CREATE TABLE someTable IF NOT EXISTS
精彩评论