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

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?

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;

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.