There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Business Applications
Tag Cloud
audio blue blue screen boot bsod compaq computer cpu crash dell drivers dvd error excel firefox format freeze freezing hard drive install internet internet explorer kb951748 lan laptop loss of internet malware memory motherboard network networking outlook outlook 2007 problem restart screen security slow sound startup trojan update virus vista windows windows xp winxp wireless zone alarm zonealarm
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: SQL Create Table; Specifiying Database Name


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
mj0769's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 07: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,863 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
22-Jul-2008, 10: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 12 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 10: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,863 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
22-Jul-2008, 11: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 4,517 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
22-Jul-2008, 12:21 PM #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 12 posts.
 
Join Date: Dec 2007
Experience: Intermediate
22-Jul-2008, 08: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 4,517 posts.
 
Join Date: Oct 2004
Location: Southwest Iowa....
Experience: Currently stupid...
23-Jul-2008, 10: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"
Closed Thread

Tags
sql

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


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 04:04 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.