I recently saw a tweet stating that you could prevent other developers from reading from a table using the SELECT * FROM TableName
by building your table in the following way:
CREATE TABLE [TableName]
(
[ID] INT IDENTITY NOT NULL,
[Name] VARCHAR(50) NOT NULL,
[DontUseStar] AS (1 / 0)
);
It's easy to see that using the SELECT *
here would try to read the blank column name as 1 divided by 0 (thus causing a divide by zero error), but without a datatype assigned to the column.
Why does SQL allow you to create a column with no assigned data type, with a name it knows will be illegal?