There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Business Applications
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: SQL Create Table; Specifiying Database Name


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
mj0769's Avatar
Computer Specs
Junior Member with 10 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 06:52 AM #1
Solved: SQL Create Table; Specifiying Database Name
Hi all,

newbie sql question.. searched forums here but couldn't find an answer...

I'm working with a series of databases. One is called 'books' and the other 'storage'. I'mm trying to create a table within the storage db called 'CustomerID'..

When I do the CREATE TABLE how do I specify which db to add it to? I've followed several samples creating db's and then using 'create table'.. and get the error 'No database selected'.. seems obvious to get that.. but haven't been able to find a solution.

Thanks
-M
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
22-Jul-2008, 09:34 AM #2
M, are you using MYSQL or something similar?
Where are you ttrying to create the From, outside the Database completely?
mj0769's Avatar
Computer Specs
Junior Member with 10 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 09:54 AM #3
ODP, thanks for the reply.

I'm using mysql with intentions of building a php-mysql app. For the CREATE TABLE I'm doing it from the command line in the mysql directory. I've modified the PATH so I can call mysql commands from anywhere.

I installed them using the xampp bundle. As for directories, it's something I could use help with too. Currently under the xampp dir' tree there are apache, mysql and php all in their own dir's. The server root is C:\xampp\htdocs. In order to run the complete app which I'm building, do I have to move everything ( apache, mysql and php) under the htdocs??
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 6,370 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
22-Jul-2008, 10:24 AM #4
m, sorry I can't help you, my expertise is Access databases followed by Excel Workbooks. I don't know any MYSQL.
slurpee55's Avatar
Computer Specs
Distinguished Member with 3,843 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
22-Jul-2008, 11:21 AM #5
By default, the table is created in the default database. An error occurs if the table exists, if there is no default database, or if the database does not exist.
The table name can be specified as db_name.tbl_name to create the table in a specific database. This works regardless of whether there is a default database, assuming that the database exists. If you use quoted identifiers, quote the database and table names separately. For example, write `mydb`.`mytbl`, not `mydb.mytbl`.
__________________
Iowa? I could have sworn this was heaven.
Well, I think I can answer this question most successfully in mime.

My theme song...
mj0769's Avatar
Computer Specs
Junior Member with 10 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 07:22 PM #6
Thanks slurpee55, that worked. I created a new db called foo and added a table called 'mynewtable' using this:
create database foo;

create table foo.mynewtable (
name varchar(20) not null,
date1 date not null,
primary key(name) );

then...I was able to view what was created using: "describe foo.mynewtable;"..

Also, you may have noticed my other q' about dir' trees of php, mysql and xampp. I didn't know if it's ok as is or if I need to move everything under the htdocs tree. I ran the commands above in the server root at 'xampp\htdocs' and was able to access the db's fine. but it worked.. so I guess the current dir' tree is ok.

Thanks! -M
slurpee55's Avatar
Computer Specs
Distinguished Member with 3,843 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
23-Jul-2008, 09:15 AM #7
Glad it worked out for you - I am not a MySQL person either, just a good googler
If it all is working, please use the button at the top of the page to mark this thread as "Solved"
Reply

Tags
sql


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:59 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.