Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Trusting Database Engine Tuning Advisor for Query TuningMirroring Hands On with Developer Edition »
    comments

    I have been tagged by Aaron Bertrand in the latest SQL meme: Tagged: 5 things SQL Server should drop. This meme is about five thing that you wished that were dropped from SQL Server. Actually I prefer that SQL Server adds stuff instead of removes stuff, I can always ingore the things I don't like. Anyhow since this is about things that should be removed, here is my list.

    Isnumeric

    The isnumeric function is something that can bring you into trouble without you even knowing it, for example run these queries

    1. select  ISNUMERIC(CHAR(9)),
    2.         ISNUMERIC('1D2'),
    3.         ISNUMERIC('.'),
    4.         ISNUMERIC('-'),
    5.         ISNUMERIC('+')

    Really a tab (Char(9) is numeric? I would be much better if SQL Server had IsInteger, IsFloat,IsTinyInteger functions or perhaps the ability to pass in the the type to isnumeric
    Something like this

    1. SELECT ISNUMERIC('123', 'TinyInt')



    Restrictions on Indexed Views

    Lookup indexed views and you will see more restrictions than you can fathom, you can't memorize these things either, there are too many. First you need a bunch of setting

    1. SET NUMERIC_ROUNDABORT OFF;
    2. SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    3.     QUOTED_IDENTIFIER, ANSI_NULLS ON;


    Why not replace that with

    1. SET CREATE_INDEXED_VIEW_SETTINGS ON

    This would be similar to ANSI_DEFAULTS, that sets 7 other settings to ON or OFF

    After you are done with all these settings you have a whole laundry list of restrictions. Some of these restriction seems a little restricting to me, I have heard that other RDBMS vendors don't have some of these restrictions in their materialized views.



    Ordered views

    Take away the ability to create an ordered view since it is ignored anyway.
    So for example if you create this view, which was working nicely in SQL Server 2000

    1. CREATE VIEW vTestSort
    2. AS
    3. SELECT TOP 100 PERCENT id FROM TestSort
    4. ORDER BY id

    This doesn't work in 2005 or 2008

    OF course you can do this and it will 'work' and I wrote about it here: Create a sorted view in SQL Server 2005 and SQL Server 2008

    1. CREATE VIEW vTestSort2
    2. AS
    3. SELECT TOP 99.99 PERCENT  id FROM TestSort
    4. ORDER BY id

    I say get rid of that, if people want the view to be in a specific order then specify ORDER BY...how lazy can you be?



    Unique constraints with one NULL value

    This is a great interview question and that is the only usefulness of this constraint. Either allow multiple NULL values or disallow NULL values.
    Of course you can now use a Filtered Index in 2008 to accomplish this

    1. create unique nonclustered index IX_LookMaMultipleNullValues on dbo.SomeTable(SomeColumn)
    2. where SomeColumn is not null;

    But not everyone is on 2008

    Functions that are very similar

    Aaron already touched upon this with timestamp and rowversion in his post. SQL Server has a bunch of function that are very similar, I think we should retire some of those. Here is a list.

    ISNULL and COALESCE
    Those are not really the same, COALESCE allows for more than 1 expressions, preserves the datatype and is ANSI standard. So why do we need ISNULL? I know, I know..someone will post that ISNULL performs better........

    CURRENT_TIMESTAMP and GETDATE()
    Banish GETDATE() and use CURRENT_TIMESTAMP instead, the only reason people (me included) use GETDATE() is because we are lazy and it is shorter. As a matter of fact use CURRENT_TIMESTAMP when you create a table and then script the table out...what do you see? It will be GETDATE()

    User functions

    1. SELECT  SYSTEM_USER,
    2.         SUSER_SNAME(),
    3.         USER,
    4.         USER_NAME(),
    5.         CURRENT_USER,
    6.         SESSION_USER

    When I tell you to capture a user which of these six will you use?




    That is it for me, I am tagging the following people
    Ted Krueger Blog / twitter: http://twitter.com/onpnt
    Michelle Ufford Blog / twitter: http://twitter.com/sqlfool
    Denny Cherry Blog / twitter: http://twitter.com/mrdenny
    Adam Haines Blog / twitter: http://twitter.com/Adam_Haines

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    1699 views
    Instapaper

    4 comments

    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) Oh I have some good ones in mind :-) I'll get mine up later. Thanks for the tag Denis.
    05/11/10 @ 09:56
    Comment from: Gareth Erskine-Jones [Visitor]
    Gareth Erskine-Jones You suggest getting rid of "ordered views". How would you do that? A view is a virtual table, and like a table, has no order.
    When you select from a view, you do of course get the results in a particular order, but that's not because your order by clause is being used to order the rows - it's actually just a side effect.
    In a view you can only specify an order by clause if you are using TOP (or FOR XML). The purpose of the order by clause in this case is to specify which rows are to be included in the result set - not the order of the result set.
    As an implementation detail, SQL server sorts the results in order to be table to return the correct rows (specified by TOP). SQL Server 2005 did this even with TOP 100%. The optimiser in 2008 is better, and sees that as all rows are being returned, there's no need for the sort.
    If you specify TOP 99.9 percent, then presumably if your table was large, you might not be returning all of the rows - so the result set is sorted to apply the TOP.

    The real problem comes because order by has more than one role - sometimes it's used to request the result set in a particular order (in which case the result set is not a relational table anymore). Elsewhere, it's used along with TOP to determine which rows to include.

    In:

    CREATE VIEW vTestSort2
    AS
    SELECT TOP 99.99 PERCENT id FROM TestSort
    ORDER BY id

    SQL Server happens to return the rows ordered by Id. This shouldn't be relied on though, any more than you should rely on the ordering of the results from:

    select distinct id from TestSort









    05/12/10 @ 09:27
    Comment from: SQLDenis [Member] Email
    SQLDenis Gareth, I have seen many people relying on this 'functionality' since in 2000 it did returned them ordered. I actually meant to say don't allow the order by clause in the view definition period.

    But Microsoft even issued a KB article with a 'fix' for this: FIX: When you query through a view that uses the ORDER BY clause in SQL Server 2008, the result is still returned in random order

    http://support.microsoft.com/default.aspx?scid=kb;en-us;926292&sd=rss&spid=2855
    05/12/10 @ 09:36
    Comment from: sqlsister [Member] Email
    sqlsister One other thing SQl Server could do without is
    user-defined data types. If they aren't going to fix them to make them so you can change them without a lot of pain, then don't even have them. As it is, I would never consider using one.
    05/14/10 @ 14:53

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)