我可以在 SQL Server 中选择 0 列吗? [英] Can I select 0 columns in SQL Server?

查看:27
本文介绍了我可以在 SQL Server 中选择 0 列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个问题比类似的创建一个没有列的表.是的,我问的是一些最会被认为毫无意义的学术性的东西.

I am hoping this question fares a little better than the similar Create a table without columns. Yes, I am asking about something that will strike most as pointlessly academic.

很容易产生 0 行(但有列)的 SELECT 结果,例如SELECT a = 1 WHERE 1 = 0.

It is easy to produce a SELECT result with 0 rows (but with columns), e.g. SELECT a = 1 WHERE 1 = 0.

是否可以产生 0 列(但有行)的 SELECT 结果?例如类似于 SELECT NO COLUMNS FROM Foo.(这不是有效的 T-SQL.)

Is it possible to produce a SELECT result with 0 columns (but with rows)? e.g. something like SELECT NO COLUMNS FROM Foo. (This is not valid T-SQL.)

我遇到这个是因为我想插入几行而不为其中任何一行指定任何列数据.例如(SQL Server 2005)

I came across this because I wanted to insert several 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
-- Invalid column name 'NO'.
-- An explicit value for the identity column in table 'Bar' can only be specified when a column list is used and IDENTITY_INSERT is ON.

可以在不指定任何列数据的情况下插入单行,例如插入 Foo 默认值.

One can insert a single row without specifying any column data, e.g. INSERT INTO Foo DEFAULT VALUES.

可以查询行数(无需从表中检索实际列数据),例如SELECT COUNT(*) FROM Foo.(但该结果集当然有一列.)

One can query for a count of rows (without retrieving actual column data from the table), e.g. SELECT COUNT(*) FROM Foo. (But that result set, of course, has a column.)

我尝试过类似的事情

INSERT INTO Bar () SELECT * FROM Foo
  -- Parameters supplied for object 'Bar' which is not a function.
  -- If the parameters are intended as a table hint, a WITH keyword is required.

INSERT INTO Bar DEFAULT VALUES SELECT * FROM Foo
  -- which is a standalone INSERT statement followed by a standalone SELECT statement.

我可以用不同的方式做我需要做的事情,但在支持退化案例方面明显缺乏一致性让我感到惊讶.

I can do what I need to do a different way, but the apparent lack of consistency in support for degenerate cases surprises me.

我通读了 BOL 的相关部分,但没有看到任何内容.我也很惊讶通过 Google 什么也没找到.

I read through the relevant sections of BOL and didn't see anything. I was surprised to come up with nothing via Google either.

推荐答案

这是 SQL 的一个重要限制,也是 SQL 在关系上不完整的原因之一.

This is one significant limitation of SQL and one reason why SQL is not relationally complete.

您可能知道,休·达文 (Hugh Darwen) 为这两个零度关系发明了名称 DUM 和 DEE.SQL 没有与它们等效的东西.

As you may know, Hugh Darwen invented the names DUM and DEE for the two zero-degree relations. SQL has no equivalent of them.

这篇关于我可以在 SQL Server 中选择 0 列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆