<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx</link><description>One of the things I always tell people that I love about consulting/mentoring work is that you see things that you just can't make up. They provide interesting material for training classes. This week I came across something that I wasn't expecting. I</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47463</link><pubDate>Mon, 04 Feb 2013 08:32:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47463</guid><dc:creator>Robert L Davis</dc:creator><description>&lt;p&gt;What about manually editing the system tables in SQL 2000 or earlier. Could you make that work? I've seen some pretty impossible things happen because people were messing around with updating the system tables manually.&lt;/p&gt;</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47464</link><pubDate>Mon, 04 Feb 2013 08:50:29 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47464</guid><dc:creator>Martijn Evers</dc:creator><description>&lt;p&gt;C. J. Date calls these relations TABLE_DUM and TABLE_DEE. TABLE_DUM has zero tuples of degree zero, TABLE_DEE has one tuple of degree zero.&lt;/p&gt;
&lt;p&gt;The reason these are important is to provide some identity relations with respect to join. Joining any table to TABLE_DEE returns the original table. Joining any table to TABLE_DUM returns TABLE_DUM. You can think of this as analogous to multiplying by 1 or 0.&lt;/p&gt;
&lt;p&gt;Unfortunately, standard SQL doesn't account for tuples of degree zero. So while it makes sense that relational theory includes these relations for completeness, SQL as written doesn't.&lt;/p&gt;
&lt;p&gt;For a good read on the fundamental nature of tables with no columns look at C.J. Dates work talking about Table Dee and Table Dum.&lt;/p&gt;
&lt;p&gt;See &lt;a rel="nofollow" target="_new" href="http://flylib.com/books/en/2.214.1.38/1/"&gt;http://flylib.com/books/en/2.214.1.38/1/&lt;/a&gt; for a description on those tables.&lt;/p&gt;</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47465</link><pubDate>Mon, 04 Feb 2013 09:27:23 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47465</guid><dc:creator>Greg Low</dc:creator><description>&lt;p&gt;Hi Martijn, I have that book and just now have re-read the sections on it. &lt;/p&gt;
&lt;p&gt;I get his justification for them (mathematically) in relational theory. JOINs to them are like multiplying by 0 or 1. &lt;/p&gt;
&lt;p&gt;I don't, however, get the point of doing it with tables. Do you have a concrete example of how they could possibly be useful if, in fact, SQL Server did support them?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Greg&lt;/p&gt;
</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47469</link><pubDate>Mon, 04 Feb 2013 10:58:51 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47469</guid><dc:creator>Martijn Evers</dc:creator><description>&lt;p&gt;Part of the issue here is SQL itself. TABLE_DEE and TABLE_DUM are quite useful in tutorial D.(They either get used to returned by operations) for example as switch&lt;/p&gt;
&lt;p&gt;There are several situations where I would prefer them even in plain SQL.&lt;/p&gt;
&lt;p&gt;1. Instead of writing SELECT * FROM MY_TABLE WHERE 1=0&lt;/p&gt;
&lt;p&gt;we write SELECT * FROM MY_TABLE,TABLE_DUM. The query engine should understand and optimize this better from a relational standpoint (no optimizer tricks needed).&lt;/p&gt;
&lt;p&gt;2. testing for existence rows: If exist(select * FROM TABLE_1) then... can be replaced by&lt;/p&gt;
&lt;p&gt;IF TABLE_1 UNION TABLE_DEE(=TRUE) THEN &amp;nbsp;(UNION= relational AND and TABLE_DEE = relational TRUE. &lt;/p&gt;
&lt;p&gt;(syntax is not helping here so TABLE_TRUE and TABLE_FALSE would be good synonyms). &lt;/p&gt;
&lt;p&gt;Note, this is the RELATIONAL if then else, not the programmable one from T-SQL. It is very powerful since we can start doing conditional joining and reusing tables/views based on conditions.&lt;/p&gt;
&lt;p&gt;Another way of looking at it is: don't use bits or Boolean scalar data types at all, but start using relations instead&lt;/p&gt;
&lt;p&gt;Use them as database wide flags encoded with tables/relations:&lt;/p&gt;
&lt;p&gt;CREATE TABLE DATABASE_DEPLOYED{} &lt;/p&gt;
&lt;p&gt;this is now equivalent to table_dum so FALSE, meaning database is not deployed&lt;/p&gt;
&lt;p&gt;INSERT VALUES() INTO DATABASE_DEPLOYED&lt;/p&gt;
&lt;p&gt;This is an empty tuple so DATABASE_DEPLOYED is now equivalent to TABLE_DEE&lt;/p&gt;
&lt;p&gt;Note, a flag just denotes true or false, but since a record/tuple also denotes a true proposition the table CREATE DATABASE_DEPLOYED(Boolean deployed PK) would denote DATABASE_DEPLOYED &amp;quot;is true is true&amp;quot; which is superfluous and actually erroneous, because what would the statement &amp;quot;is true is false&amp;quot; mean?&lt;/p&gt;
&lt;p&gt;For SQL these tables would allow for cleaner SQL with less &amp;quot;if then else&amp;quot;, allow for case statements to collapse result-sets etc. But to be really useful I think some extension on T-SQL would also be in order, else it will be window dressing. (Some will argue not even to bother with SQL at all since it is not relational to begin with).&lt;/p&gt;
&lt;p&gt;A good candidate that we can implement with dee and dum would be a relational IF statement.&lt;/p&gt;</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47479</link><pubDate>Mon, 04 Feb 2013 20:55:34 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47479</guid><dc:creator>Martijn Evers</dc:creator><description>&lt;p&gt;@Greg, Did my follow up post disappear?&lt;/p&gt;</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47483</link><pubDate>Mon, 04 Feb 2013 23:35:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47483</guid><dc:creator>Greg Low</dc:creator><description>&lt;p&gt;Sorry Martijn, which post? (There is one where you give examples)&lt;/p&gt;
</description></item><item><title>re: Can a table have no columns?</title><link>http://sqlblog.com/blogs/greg_low/archive/2013/02/04/can-a-table-have-no-columns.aspx#47488</link><pubDate>Tue, 05 Feb 2013 10:08:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47488</guid><dc:creator>Martijn Evers</dc:creator><description>&lt;p&gt;@Greg,&lt;/p&gt;
&lt;p&gt;Ah, Now I see my first follow up post. I was afraid it got dropped.&lt;/p&gt;
&lt;p&gt;To Reiterate,&lt;/p&gt;
&lt;p&gt;TABLE_DEE AND TABLE_DUM are tables encdoding TRUE and FALSE. Relational operators can use this (like EXCEPT,INTERSECTION,UNION, Relational IF, Relational EQUAL). With SELECT, MERGE and other typical operational SQL statements we sometimes can use them as well, but there is no consistent usage pattern AFAIK, just a list of handy tricks and query engine optimizations.&lt;/p&gt;
&lt;p&gt;For creating base tables it does make sense, but we certainly can design around the limitation of not having table_dee and table_dum.&lt;/p&gt;
&lt;p&gt;If we ever get some additional serious relational operators (EQUAL, IF) I would definitely want to see table_dee and table_dum.&lt;/p&gt;</description></item></channel></rss>