• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Scripting mySQL to create db and tables in one script

Hi Guys,

I have mySQL running on a Windows 2008 box. It's fine, I've setup databases, tables, etc.

However, I'm trying to get some scripts running.

I have a script to create a database, and I have scripts to create tables.

However, if I run the following script (and the db doesn't exist), the table is being inserted into an existing database.

Is there something I can add to this code to keep the table that is created after the db to be inserted into the same DB?

I want tbl_adCategories inserted into dbAds. I'm guessing I need to declare dbAds in the create table script?

CREATE SCHEMA `dbAds`;

CREATE TABLE `tbl_adCategories`(
`categoryID` int(11) NOT NULL AUTO_INCREMENT,
`categoryParentName` varchar(30) NULL,
`categoryName` varchar(31) NOT NULL,
`categoryStatus` varchar(16) NOT NULL,
`categoryParentID` char(10) NULL,
PRIMARY KEY (`categoryID`),
UNIQUE KEY `categoryID_UNIQUE` (`categoryID`))
 
Looking at that code, do you see any problems with it? I'm going to be writing up a script that creates 100's of tables. The code itself works, and it looks ok to me. Just curious more than anything.
 
CREATE SCHEMA `dbAds`;

USE 'dbAds';

CREATE TABLE `tbl_adCategories`(
`categoryID` int(11) NOT NULL AUTO_INCREMENT,
`categoryParentName` varchar(30) NULL,
`categoryName` varchar(31) NOT NULL,
`categoryStatus` varchar(16) NOT NULL,
`categoryParentID` char(10) NULL,
PRIMARY KEY (`categoryID`),
UNIQUE KEY `categoryID_UNIQUE` (`categoryID`))



that look ok?
 
Back
Top