Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using hyphen (-) in table name for MySQL

Status
Not open for further replies.

401R

Programmer
Oct 31, 2001
23
US
Here is the code:
querystring = "Create Table " & workweekwafer & " (stepno int(5))"

Set RS = Conn.Execute(querystring)

workweekwafer = 0304-102

I get this error
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[MySQL][ODBC 3.51 Driver][mysqld-4.0.13-nt]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '0304-102(StepNo int(5), StepName varchar(50))' at line 1

I tried using

querystring = "Create Table [" & workweekwafer & "] (stepno int(5))"
but it still give me the same error

If I change the hypen (-) to and underscore (_), it has no problems creating the table. What is the VBSCRIPT command to type a hyphen, like I know for a quote mark it is char(34). Maybe that will work.

Well, I have a problem that it creates the table in the DB and I guess it tries again and give me an error that the table already exists when it should move on to another page, but that is a different problem for a different thread.

Any help is extremely appreciated.
 
Ok the I can use chr(45) to insert a hyphen , but I still get the same error.
 
try encapsing it with [ ]

eg:
querystring = "Create Table [" & workweekwafer & "] (stepno int(5))"


_____________________________________________________________________
onpnt2.gif

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
I tried that [], I had typed it in , but I guess with all the editing to get the problem across, I must have deleted it by accident.

But the [] does not work either. If I use Navicat to create tables in MySQL I can create a table with a hypen in the name, so it should not be an issue, it's gotta be something in the way VBSCRIPT ASP send the hyphen across.
 
strsql = "create table [" & workweekwafer & "] (stepno int(5))"

doesn't work?
 
[lol]

I didn't even notice the formatting

eg:
Code:
strsql = "create table [" & workweekwafer & "] (stepno int(5))"

_____________________________________________________________________
onpnt2.gif

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
No
strsql = "create table " & workweekwafer & " (stepno int(5))"

does not work, it gives me the error.

Any other Ideas?

 
Are you using the brackets though?

I.E.

create table [my-tablename] (stepno int(5));
 
I was just reading through the manual a bit as it's been a few months sense I palyed with MySQL and it seems to me that this is a invalid naming convention for a table name

in all MySQl interpruts that as a mathmatical expression. so if you say
table-name it try's to in all take table and subtract name from the given val.

I also in presonal mode think this is a bad naming process and have never attmepted to try it as it seems error prone. I would suggest replacing the "-" with underscores _
which is more of the standard of naming conventions


___________________________________________________________________
onpnt2.gif

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
yeah, it makes sense to use the underscore, I was just trying ot keep our standard part naming convention, which goes by eg. 0304-102. I am already working on a work around to just name the tables with an underscore as you suggest and have the code in ASP change the underscore to a hyphen for displaying on the the web page. I just kept trying since I figured it would work, it is just a way of figuring out how.

The manual says that for table names it allowes "Any character that is allowed in a file name, except '/' or '.' " and using Navicat I can create tables wth a Hyphen. I found a web site that explains, of course if I use the shell command, I can create a table name with a hyphen if I put the command in single quotes
eg. 'Create TABLE 0304-102'

It is better naming convention to use the underscore, I agree, I guess I just got stuck on getting it to work since I know it is possible.

Thanks for everyones help and responses.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top