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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create table column named foreign 1

Status
Not open for further replies.

machinetype

IS-IT--Management
Aug 8, 2002
48
0
0
US
Hi,

I'm using MySQL 4.1.7 on FreeBSD 5.3. I'm trying to add a column named foreign and it keeps kicking back an error. I realize foreign is a function call of sorts...but is there a workaround? I've tried adding it using the add table syntax and alter table...both are unsuccessful.

Thanks.
 
'foreign' is a reserved word in sql. You can name it foreign if you quote it properly, but you'd have to specially quote it every time you referenced it. Why not just think of a different name.
 
Foreign" as in foreign movies. I'm running php which fetches the column names, returns them with checkboxes, allows the user to select multiple check boxes, then returns movies in the specified genres.

Renaming it may be confusing for the user, unless there's some way to alias it, but that would most likely muck up my script....

I've tried quoting it with double, single and back ticks but nothing seemed to work...am I not quoting properly?....

Thanks for the suggestions.
 
To create a table column with reserved words use backticks in your sql statement.

EX:

INSERT INTO table (`foreign`,`desc`) VALUES ('blah blah','more blah');

 
I'm actually trying to *create* a table with a column named foreign.

eg.

create table movies (
-> title varchar(20),
-> director varchar(20),
-> independent tinyint(1) NOT NULL DEFAULT '0',
-> foreign tinyint(1) NOT NULL DEFAULT '0'
);

I have also tried to first create the table without foreign and adding later with alter table to no avail:

alter table movies add foreign tinyint(1) NOT NULL DEFAULT '0' after independent;

Thanks.
 
D'oh...thought I tried that as my first step...apparently not because it just worked. Thanks.

Someone stated it was a very bad idea...is this because it's breaking standards?... or can it cause other damage?....
 
Code:
create table "insert" 
( "references"  varchar(11),
  "timestamp"  date,
  "varchar"    timestamp default now(),
  "datetime"   integer,
  "distinct"   decimal(2,1),
  key "order by" ( "references" ),
  constraint "distinct key" 
    foreign key ( "distinct" )
    references "on delete cascade" ( "limit" )
);

mod: +1; ludicrous

:)
 
machinetype:
It's a bad idea because "foreign" is a MySQL reserved word. Using reserved words for identifiers is simply a bad practice.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top