I hope this question will be slightly better than the similar Create a table without columns . Yes, I ask about something that will hit most of all as pointless academic.
It is easy to get a SELECT result with 0 rows (but with columns), for example. SELECT a = 1 WHERE 1 = 0 .
Is it possible to get a SELECT result with 0 columns (but with rows)? , eg. something like SELECT NO COLUMNS FROM Foo . (This is not valid T-SQL.)
I came across this because I wanted to insert multiple rows without specifying any column data for any of them. e.g. (SQL Server 2005)
CREATE TABLE Bar (id INT NOT NULL IDENTITY PRIMARY KEY) INSERT INTO Bar SELECT NO COLUMNS FROM Foo
You can insert one row without specifying column data, for example. INSERT INTO Foo DEFAULT VALUES .
You can request row counting (without extracting the actual column data from the table), for example. SELECT COUNT(*) FROM Foo . (But this result set, of course, has a column.)
I tried things like
INSERT INTO Bar () SELECT * FROM Foo
and
INSERT INTO Bar DEFAULT VALUES SELECT * FROM Foo
I can do what I need to do it differently, but the apparent lack of consistency in supporting degenerate cases surprises me.
I read the relevant BOL sections and did not see anything. I was surprised to not come up with anything through Google.
sql-server tsql sql-server-2005
Woody zenfell iii
source share