FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


What is the Difference?





GameFreak
Hey, I'm a beginner at MySQL so could you please help me out a bit..??

I have two sets of coding here..... what exactly is the difference in them? I haven't used quotes in one and I have in another.....Please tell me....

Code:

CREATE TABLE `table` (
`table_id` int(11) NOT NULL default '0',
`user_id` int(11) NOT NULL default '0', 
PRIMARY KEY (`table_id`)
)


Code:

CREATE TABLE table (
table_id int(11) NOT NULL default 0,
user_id int(11) NOT NULL default 0, 
PRIMARY KEY (table_id)
)
hexkid
The first statement does not give an error; the second gives an error.

"table" (in any case combination) is a MySQL reserved word. You cannot use it without the quotes, and you really shouldn't use it even with the quotes.

The quotes force MySQL to use the quoted name even if it's "illegal".
GameFreak
Well, so in MySQL, you should only use quotes when using an illegal term, other wise there is no use for using quotes?
hexkid
GameFreak wrote:
Well, so in MySQL, you should only use quotes when using an illegal term, other wise there is no use for using quotes?


Read the section 9.2. Database, Table, Index, Column, and Alias Names from the MySQL manual
http://dev.mysql.com/doc/refman/5.0/en/legal-names.html wrote:
An identifier may be quoted or unquoted. If an identifier is a reserved word or contains special characters, you must quote it whenever you refer to it.
ritesh26
Yes hexkid is right. you can use reserved words with quotes but not without qoutes. If you use it will give sql error.
GameFreak
And what about the "`table_id` int(11) NOT NULL default '0', " part?

Does the same rule apply here to the '0' as well? Can it be unquoted as well?
hexkid
GameFreak wrote:
And what about the "`table_id` int(11) NOT NULL default '0', " part?

Does the same rule apply here to the '0' as well? Can it be unquoted as well?


I'd write it unquoted, but I believe it doesn't matter.
I prefer to write numbers without the quotes to more easily distinguish between strings and numbers. Try this:
Code:
SELECT 3-2 = '1'




ATTENTION: You're dealing with two different quotes here; the normal single quote ( ' ) and the "special" back quote ( ` )

You use the back quote for field names or table names when you want to use a reserved word in them
Code:
select `table` from `order` where `select`=0


And you use the single quote (or the double quotes) to delimit a string
Code:
select foo from bar where qux='hexkid'
Related topics
Whats the difference of FRIH$ and Points?
How much do fans cost in a computer store?
Image gallery / host ... what's the difference?
What's the difference?!
Smart people
What is the difference between HTML and XHTML?
D difference between Anime and Tokusatsu... anyone know??
CPannel and DirectAdmin
Difference between a Jr. Admin & MOD
Ram Difference?
DVD -R and DVD +R
Difference between watch & wife.
Is there a difference between "I know" and "I
Difference between Contests and Marketplace.
Name a (wacky?) English language cultural difference.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.