Jump to content

How can I create a fieldname having symbols in it like #?


joseph

Recommended Posts

You can't use # in MySQL table names # is a reserved character which means from here to the end of the current line is a comment and should be ignored  - SO effectively your command becomes

 

CREATE TABLE EMPLOYEE (

E

EFNAME VARCHAR(20),

ELNAME VARCHAR(20)

);

 

which is why the first field is named EEFNAME as the white space is removed

Link to comment
Share on other sites

Thanks Ben. I still cannot create the S# field name I enlclosed them in backticks like `S#` or (`S#`)

 

SQL query:

CREATE TABLE EMPLOYEE(
`E#` NUMBER( 5 ) NOT NULL ,
EFNAME VARCHAR( 20 ) ,
ELNAME VARCHAR( 20 )
)

MySQL said: Documentation
#1064 - 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 'NUMBER(5) NOT NULL,
EFNAME VARCHAR(20),
ELNAME VARCHAR(20),
' at line 2 

 

I think Tyche is right, maybe it is possible with other SQL applications like SQL server?

Link to comment
Share on other sites

I have successfully executed this to create table (MySQL 5.0) and also added and reteived data

 

DROP TABLE IF EXISTS `test3`.`widget`;
CREATE TABLE `widget` (
  `W#` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY  (`W#`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Link to comment
Share on other sites

CREATE TABLE EMPLOYEE (
E# NUMBER(7) NOT NULL,
EFNAME VARCHAR(20),
ELNAME VARCHAR(20)
);

 

When I run these sql statements in PhpMyAdmin it does not add E# but changes the EFNAME to EEFNAME. Thanks.

Just don't do this... I doubt you can justify this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.