• L' Eomot Inversé (1/29/2013)


    Sean Lange (1/29/2013)


    It seems that today's QOTD fits in nicely with this discussion. A very simple method was presented there using a constraint to allow a table to have only 1 row.

    CREATE TABLE Test_Table (PK BIT PRIMARY KEY, Comment VARCHAR(10));

    ALTER TABLE Test_Table ADD CONSTRAINT PK_check CHECK (PK <> 0);

    That is about as simple as you can make it.

    I think CREATE TABLE Test_Table (PK BIT PRIMARY KEY CHECK(PK <> 0), Comment VARCHAR(10));does the same thing and is easier to read. Of course it doesn't provide a user-specified name for the check constraint, but ....

    True, that is how I would write it if I were coding it myself. I just copy pasted from the question. 🙂

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/