Why does WordPress prefix its column names with the table name? [closed] - sql

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
I noticed that in a recent update WordPress decided to change all of its column names to include the table name prefix. WHY?!
The wp_posts table now has a column called post_title, for example. It used to just be title. I don't understand the reason for this change. There must've been one, yes?
I just don't understand what possible reason there could be since in SQL you can refer to things like table.column. Also, it must've been really difficult to change all of the code.

Perhaps to prevent confusion when making joins with tables having similar column names.

There is no good reason for doing this, plus it makes maintenance much more difficult.
There is no confusion if columns are specified like:
SELECT p.title, s.title FROM wp_posts p JOIN site s ON (p.site_id = s.id);

Related

SQL group by - can it be this simple? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
can someone please check if this is correct?
Not sure if my answer to Q6 is correct, I am not sure if the group_by I am using is right or not, the rest I think is ok
Thanks
You are close. You need to:
Use COUNT() instead of SUM().
There's no need to use the HAVING clause.
Optionally, you can add aliases to the columns, so they become easier to read.
Your query should look like:
select a.author_id, count(*) as titles, sum(b.quantity_ordered) as units
from a join b on a.book_id = b.book_id
group by a.author_id

SQL naming convention: Adding data type to column name [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
As a developer, a common mistake that I keep on repeating is assuming the data type of a column. I have read multiple articles regarding SQL column naming convention but have not seen any reference regarding data type as part of the column name - specifically for SQL Server.
E.g. Revenue_f for float, Organization_v for varchar, AccountNumber_i for integer and so on.
This must have been thought of already before but I want to know the reason why it is not being used, or an expert's input regarding the matter; pointing me to the right article/documentations will be greatly appreciated.
That is a horrible naming convention. Consider how awful it would be if you need to change AccountNumber to a character datatype. Do you then go back and rename the column and change every single query everywhere? Or do you leave the suffix in your column name even though it is no longer accurate? If you want to know the datatype of a column the ONLY way is to look at the definition of the table.
Also, a single character really is kind of useless. How do you handle nvarchar vs varchar? And what about the scale?
P.S. Even though I wrote an answer I am voting to close this question because it is primarily opinion based and as such is considered off topic for SO.

Database table columns names [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have noticed that some people in database columns instead of for example id, user, addressare using something like h_id, e_user, f_address etc...
Is that some kind of security aspect? or maybe these are some shortcuts of words?
Its because there might be many id fields like user_id,category_id,that's why they use so that code is understandable.
And talking about columns name like f_address, they are just shortcut for say first address. It doesn't have anything to do with security but to increase the query readability use proper name to fields so that people can understand just by seeing column name what data it saves.
If there are fields like category_id and sub_category_id , it is understandable from the field name, but if i denote it using c_id and s_id, its hard to depict.
Well, 'User' is a security object in SQL Server, so using that is kind of scary. 'ID' and 'address' are way too generic to provide any semantics when used as attribute names.
If a purpose of design is to be maintainable and readable, then there some words that simply don't work.
Definitely not security related.
Some use it for readability or speed (you don't have to remember which table you gave a certain name->see following example) when writing queries.
i.e.
select a.name, b.name from table1 a join table2 b on a.id=b.id
Like this you have to remember that table1 is named a and table2 is named b etc.
But if you use tablename_field (which you can shorten by using only the first letter of the tablename). That way you never have duplicate fieldnames when creating join queries.

Do table names with [Name1].[Name2] pattern differ from normal tables? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When I look at Microsoft's sample AdventureWorks database, I see the table names follow a pattern such as:
[Person].[Address]
Does this kind of specification differ from a normal pattern such as:
PersonAddress
Is it only for readability or is there some other point to it?
It's SchemaName.TableName
So [Person].[Address] != PersonAddress
Instead it'll be Person.Address
The [] are optional, they exist because if you have special characters, or a reserve word in the object name, you will not be able to call the object without them.
For example select last name from people; is not going to work,
instead you need select [last name] from people;
You can find more information here.

Fulltext index query - illogical [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a fulltext index on my table but am getting weird results...
Think a table of current Toys... (huggle buddy is "hot" apparently at the moment)
If a I search for Huggle on my table the results brought up are "Huggle Buddy" toys and I get 12 results...thats fine, perfect.
But if I search for "Huggle Buddy" I get almost 500 results, which is ok as i know its searching both words and combinations, but, the items with Huggle Buddy in the title do not appear first, how do i fix that? e.g. Is there an order by scoring?
Put the search term in quotes so it will only search for an exact match. You'll only get results that contain the exact match "Huggle Buddy".