What are the pros and cons of using `select table_name. * `?

I heard that this is the wrong way to write queries in general, but I wonder what people are saying to new SQL users.

Is it really bad shape or just lazy?

Thus, in order not to require too much opinion on this subject, what good reasons are used for this in queries, except that you do not need to enter the name of each field. Also, do these reasons outweigh the harm in it?

+5
source share
4 answers

When your program knows the structure of your table at compile time or through configuration, using is select *not a good idea: any change in the structure of your table can disrupt the structure of the results returned from the query, which ultimately leads to runtime errors.

However, there are cases when it *is indispensable. In particular, if your program "learns" dynamically from the structure of your tables, reading the metadata returned from the query, using the "all columns" query allows your program to dynamically change the changes in your tables.

It goes without saying that using *SQL Studio / SQLPlus / etc for special queries in your favorite flavor. very common and convenient.

+11

* .

* , .

, , , .

+3

select * . . :

create table alpha (int id, int value);
create table beta (int value, int id);

, , . . , .

, , . (, , , - / , .

.

+1

SQL Antipatterns " ".

- . '*', , . , , .

, , blob , , , - .

SELECT *, , , , , blob - , , , , , , , . , .

SELECT *, , - . , .

SELECT *, , , .

+1
source

All Articles