Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I Always Fully Qualify Column Names In SQL?

Out of interest when working with SQL statements should I always use the fully qualifed column name (tablename.columnname) even if only working with one table e.g.

SELECT table.column1, table.column2 FROM table
like image 666
Nick Allen Avatar asked Feb 17 '09 15:02

Nick Allen


People also ask

What does fully qualified mean in SQL?

A fully qualified procedure name is a three-part name. The first part is a location name that identifies the DBMS at which the procedure is stored. The second part is the schema name of the stored procedure. The third part is an SQL identifier.

What is a qualified column name?

A qualifier for a column name can be a table name, a view name, an alias name, a synonym, or a correlation name. Whether a column name can be qualified depends, like its meaning, on its context. In some forms of the COMMENT and LABEL statements, a column name must be qualified.

When should you use column alias?

Aliases can be useful when: There are more than one table involved in a query. Functions are used in the query. Column names are big or not very readable.

What are valid column names in SQL?

Column names must contain only A to Z, 0 to 9, and underscore (_) characters. Column names can contain multiple underscores. The column name must not be very generic. Avoid words such as term, multiplier, description, name, code, and so on.


1 Answers

It's better if you do - it doesn't add any complexity, and it can prevent errors in the future.

But in a well-defined system, you shouldn't have to - it's like namespaces in programming languages. The ideal is not to have conflicts, but it can clutter the code with the superfluous use of explicit names.

-Adam

like image 173
Adam Davis Avatar answered Oct 26 '22 17:10

Adam Davis