shane18 Posted February 7, 2010 Share Posted February 7, 2010 Is it good programming to put a ` around all of your tables, and columns in all of your statements? Also can someone explain to me what the ` does? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 7, 2010 Share Posted February 7, 2010 i think it is better to include it than not to for example if in the future they make it a necessay requirement you will just have to go back and recode everything. I find it a real pain as my keyboard doesn't seem to have the `symbol so i am always copying and pasting it Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 7, 2010 Author Share Posted February 7, 2010 Whats it do though? For example... title don't work... `title` does work Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 7, 2010 Share Posted February 7, 2010 specifies the table and column just good grammar i guess. Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 7, 2010 Author Share Posted February 7, 2010 so more less it tells the computer that its not a special function or etc.... it tells it that it is a table/column name? Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 7, 2010 Share Posted February 7, 2010 I don't think that they will require that in the future, otherwise a huge amount of sites won't work. this ` exists in the top left of the keyboard, next to the key 1!, right under the Esc key. Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 7, 2010 Author Share Posted February 7, 2010 Can someone SIMPLY tell me why u should put the ` around table/column names? Quote Link to comment Share on other sites More sharing options...
abazoskib Posted February 7, 2010 Share Posted February 7, 2010 what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work. Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 7, 2010 Author Share Posted February 7, 2010 omg man thanks for that example that was pro Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 7, 2010 Share Posted February 7, 2010 what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work. I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with. For the future, if this thing happens in the later versions of MySQL, people won't use it and it will fail because people will stick to the older version because their sites are coded without ` so they are not going to go to each and every SQL statement and add this ` to each and every field and table, this is ridiculous. Even if they did that, then they will be repeating the same mistake with XHTML 1.1 and XTHML 2.0 cheers! Quote Link to comment Share on other sites More sharing options...
abazoskib Posted February 8, 2010 Share Posted February 8, 2010 what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work. I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with. Do you doubt this from your extensive knowledge of databases and in particular mysql? Please. Why don't you try it yourself. "create table `from`(test int primary key)". That's exactly why you would use ` because IT IS A RESERVED WORD. Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 8, 2010 Share Posted February 8, 2010 what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work. I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with. Do you doubt this from your extensive knowledge of databases and in particular mysql? Please. Why don't you try it yourself. "create table `from`(test int primary key)". That's exactly why you would use ` because IT IS A RESERVED WORD. excuse me, my knowledge is not extensive in SQL, I have not written any SQL statement in ages, however, why would a reasonable programmer give a table such name? a reversed word? don't tell me that he ran out of words lol. This way he is forcing himself to use this ` in each and every statement in his SQL's which sucks. Anyway, you need to take care of millions of web sites that have their SQL's without ` and convience them all to rewrite their code or look for every piece of SQL in their code. good luck for those who want to put ` in their SQL, I promise I won't put any lol, in fact I don't even write SQL's but even if I have to, I won't because its ridiculous. Quote Link to comment Share on other sites More sharing options...
abazoskib Posted February 8, 2010 Share Posted February 8, 2010 what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work. I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with. Do you doubt this from your extensive knowledge of databases and in particular mysql? Please. Why don't you try it yourself. "create table `from`(test int primary key)". That's exactly why you would use ` because IT IS A RESERVED WORD. excuse me, my knowledge is not extensive in SQL, I have not written any SQL statement in ages, however, why would a reasonable programmer give a table such name? a reversed word? don't tell me that he ran out of words lol. This way he is forcing himself to use this ` in each and every statement in his SQL's which sucks. Anyway, you need to take care of millions of web sites that have their SQL's without ` and convience them all to rewrite their code or look for every piece of SQL in their code. good luck for those who want to put ` in their SQL, I promise I won't put any lol, in fact I don't even write SQL's but even if I have to, I won't because its ridiculous. It basically only sucks ONCE when you write your application. "from" would seem like a popular table name choice to me, even though i personally wouldn't use it. its also comparable to using {} to mark variables within a PHP string i.e. $mad_lib = "The bread basket was full of {$adjective} bread..." Some people dont do it, or dont like it, but I like it because its easier to pick apart variables just by scanning it quickly. Same with ` Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 8, 2010 Share Posted February 8, 2010 As said before, backticks (``) are used to indicate that given word is a table/column identifier. Using it you can call your tables with reserved words, use whitespace in names or even call your table `.` if you're crazy enough (don't try it at home, I did it for you). For portability reasons (ability to move your application to different database systems) backticks should NOT be used (because (1) they're not part of stadard SQL, and (2) it forces you to give sensible names to your tables/columns) Quote Link to comment Share on other sites More sharing options...
Hussam Posted February 8, 2010 Share Posted February 8, 2010 For portability reasons (ability to move your application to different database systems) backticks should NOT be used (because (1) they're not part of stadard SQL, and (2) it forces you to give sensible names to your tables/columns) This should be enough for these clumsy backticks to not to be used. I own you one Mchl. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.