My first Query

  • Hello ! Guys

    I have newly joined this forum, I have a query regarding a create table statement which I have generated successfully and its look like :

    IF OBJECT_ID('dbo.Nums','U') IS NOT NULL DROP TABLE dbo.Nums;

    CREATE TABLE dbo.Nums( n INT NOT NULL PRIMARY KEY);

    My question is what stands for 'U' here , and what if I don't want to mention the 'U' here?

    I haven't experimented that really.

    Thanks

    Subhro

  • Here the 'U' is the object type which is a table.if you dont put 'U' still the query works, but think if you are having a SP or a Funtion with the same name as table it will give conflict.

    the diffrent types are as follows:

    D

    F

    IT

    P

    PK

    S

    SQ

    TR

    U

    UQ

    V

  • Thanks Sharath!

  • mukherjee.subhro (5/3/2010)


    My question is what stands for 'U' here , and what if I don't want to mention the 'U' here?

    I haven't experimented that really.

    IF OBJECT_ID(N'dbo.Nums', N'U') IS NOT NULL

    DROP TABLE dbo.Nums;

    GO

    CREATE TABLE dbo.Nums (n INTEGER NOT NULL PRIMARY KEY);

    The U means only match with user tables.

    You can use any object type there like V for a view, see sys.objects in Books Online for a list.

    Otherwise, it checks for any object with the name given.

  • Got it ! Thanks

    subhro

  • Sorry for the duplication - I didn't see the reply from sharath.chalamgari because I had the reply window open for a while before submitting it :pinch:

Viewing 6 posts - 1 through 6 (of 6 total)

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