Empty TABLE

  • Interesting question. Made me think a little since I obviously never tried it before.

    Guessed it right because I was sure there had to be some sort of validation to prevent this.

    ---------------
    Mel. 😎

  • Thanks for the question.

  • Victor Kirkpatrick (2/13/2015)


    Yeah that was a good one... have never contemplated dropping the only column in a table. Interesting to see the error.

    +1

  • 'A table cannot be created without a column.' : is really irrelevant, given the context, and nature of tables in Sql Server. The table was created with a column. An attempt to drop the column happened.

  • mwpowellhtx (2/16/2015)


    'A table cannot be created without a column.' : is really irrelevant, given the context, and nature of tables in Sql Server. The table was created with a column. An attempt to drop the column happened.

    Yes, quite so. And the reference is utterly irrelevant to the question and answer too.

    But despite that, it's still a nice question. quite scary that more than 20% got it wrong, though.

    Tom

  • It's true. However, the lessons I take from these is to always at least run it on my favorite Sql Server fiddler, if not a local database instance. 🙂

  • A table cannot be created without a column.' : is really irrelevant, given the context, and nature of tables in Sql Server. The table was created with a column. An attempt to drop the column happened.

    Yeah,you are right!!! Thank you for pointing it. I will be careful next time.

  • Raghavendra Mudugal (2/13/2015)


    Thank you for the post, very interesting one.

    (so, 63 people thought that they can create a table with no cols; if this becomes real, I am not sure how and where this can be used; would be cool though if they come up with a real-time situation where this is a must...):-D

    There is in fact a use for column-less tables - just not in the external surface area.

    When analyzing execution plans, you will sometimes see that data flowing between two operators (which, admittedly, is not truly a table) that has no rows. And there is even an operator that stores an internal "virtual table" with zero columns (the Row Count Spool operator)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • So in the instance of execution plans, its not truly columnless table, but rather rowless table (view, etc). i.e. for outer joins...

  • mwpowellhtx (2/20/2015)


    So in the instance of execution plans, its not truly columnless table, but rather rowless table (view, etc). i.e. for outer joins...

    No, no, you misunderstand. A rowless table is nothing special, just execute a CREATE TABLE, a DELETE without WHERE or a TRUNCATE to get one (the latter two best not on your prod server;-))

    In an execution plan, there can be operators that pass each others rows with zero columns. You can see this by looking at the operator properties (the Output List property is missing in those operators), or by looking at the estimated row size of the data stream (it will be 9 bytes, which is exactly the number of bytes for the per-row overhead - so no extra space used for any columns).

    If you can make it to London on March 4, come see my "Understanding Execution Plans" training day. I have one of these in at least one of the demos. I understand from the organization that I already have a pretty large crowd, but that there are still some seats available.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Oh, I see. The operators involved. Interesting. I'll look for that, thank you.

  • easy peasy!

Viewing 12 posts - 16 through 26 (of 26 total)

You must be logged in to reply to this topic. Login to reply