Be careful with Open Table

Yes, you were already aware of 40 or 50 reasons not to use Open Table.  I have one more.  Say you are creating a table with a composite key that includes a binary column.  An example I came across recently was a table that captures additional data not covered by CDC (e.g. username).  So, I created this table:

CREATE TABLE dbo.CaptureDetails
(
  StartLSN BINARY(10) NOT NULL,
  EndLSN BINARY(10) NOT NULL,
  ActionType INT NOT NULL,
  Username VARCHAR(32) NOT NULL,
  PRIMARY KEY(StartLSN, EndLSN, ActionType)
);
GO

— now I actually use cdc schema not of dbo, and populate
— this via a trigger on the CDC change table, but for ease
— of reproduction, let's just jimmy some data in there:

INSERT dbo.CaptureDetails(StartLSN, EndLSN, ActionType, Username) 
SELECT 0x0000001A000001360013, 0x0000001A000001360012, 2, 'sa'
UNION SELECT 0x0000001A0000013A0003, 0x0000001A0000013A0002, 2, 'sa'
UNION SELECT 0x0000001A0000013B0004, 0x0000001A0000013B0002, 3, 'sa'
UNION SELECT 0x0000001A0000013B0004, 0x0000001A0000013B0002, 4, 'sa'
UNION SELECT 0x0000001A000001490013, 0x0000001A000001490012, 2, 'sa'
UNION SELECT 0x0000001A0000014C0003, 0x0000001A0000014C0002, 2, 'sa'
UNION SELECT 0x0000001A000001560003, 0x0000001A000001560002, 2, 'sa'
UNION SELECT 0x0000001A000001570003, 0x0000001A000001570002, 2, 'sa'
UNION SELECT 0x0000001A000001590004, 0x0000001A000001590002, 3, 'sa';
GO

Now, right-click this table in Object Explorer, and choose "Open Table". Pick any row where c = 2, and change the data from "sa" to "what?".  Close the table and then run Open Table again.  Whoops!  You updated more than one row.  Strange, huh?  Note that while I found this testing CDC in Katmai, this symptom is equally destructive in SQL Server 2005.

I have filed this defect (with a few more details) at the following URL, and encourage you to vote:
http://web.archive.org/web/*/https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=289541

Aaron Bertrand

I am a passionate technologist with industry experience dating back to Classic ASP and SQL Server 6.5. I am a long-time Microsoft MVP, speak frequently at conferences, and write at SQLPerformance and MSSQLTips. I recently joined the team at Wayfair and hope to blog about some of the scale challenges I've already started helping to solve.

3 Responses

  1. SJ says:

    Actually, I would love to see the list of 40-50 reasons to not use Open Table.  My programmers and Jr. DBA do this all the time and it annoys the heck out of me.  And then they complain of performance.  
    Really, I would love to find a way to remove this menu item from the SSMS.  Know of anything?
    Thanks
    SJ
    <a href="http://feeds.feedburner.com/~r/MathomSolutionsBlog-it/~6/1"><img src="http://feeds.feedburner.com/MathomSolutionsBlog-it.1.gif&quot; alt="Mathom Solutions Blog-IT" style="border:0"></a>

  2. AaronBertrand says:

    Good news, SJ!  In SQL Server 2008, Open Table is being replaced by the following menu items:
    SELECT n1 ROWS
    EDIT n2 ROWS
    n1 and n2 will be configurable via Tools | Options.
    If you choose the SELECT option, it will launch a new query window, with SELECT TOP <column list> FROM <selected table>.  There will be a nice big comment in there to add an ORDER BY so that which n1 rows you receive is not arbitrary, and so that it is not misleading users into thinking TOP has some meaning without ORDER BY.
    If you choose the EDIT option, you will get the datagrid like you get with Open Table today.  In this case, there isn't a good way to make it very obvious that if the user wants a specific set of rows, they should switch to the SQL view and add an ORDER BY clause.

  3. AaronBertrand says:

    As for the 40 or 50 reasons not to use Open Table, if you are familiar with Connect, start here:
    http://web.archive.org/web/*/https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=264592
    In addition to the problem I outline there, I also reference a whole slew of Connect items that mention Open Table.