confusion in setting up superkey

  • Dear Sir,

    I am in great trouble, my problem is I have a vendor Table

    which consist of some fields. I explaining the structure below

    Table<Vendor>

    --------------

    fields name

    -----------

    PKID int

    VENDORID int

    VENDORNAME varchar (50)

    ADDRESS varchar(50)

    CITY varchar(15)

    I have set Primary key on PKID (cluster index)

    I have set non cluster index on (VENDORID,VENDORNAME/ADDRESS) FIELDS

    now I want to set superkey on (VENDORID+ADDRESS+CITY) which identify unique record.

    is it right structure for creating index

    please give me suggestion

    thanks in advance

    Debasis

  • You can create a unique non clustered index on (VENDORID+ADDRESS+CITY) since your primary key is already specified. You can specify a unique key constraint when creating the table also.

  • deba_20032004 (10/15/2012)


    Dear Sir,

    I am in great trouble, my problem is I have a vendor Table

    which consist of some fields. I explaining the structure below

    Table<Vendor>

    --------------

    fields name

    -----------

    PKID int

    VENDORID int

    VENDORNAME varchar (50)

    ADDRESS varchar(50)

    CITY varchar(15)

    I have set Primary key on PKID (cluster index)

    I have set non cluster index on (VENDORID,VENDORNAME/ADDRESS) FIELDS

    now I want to set superkey on (VENDORID+ADDRESS+CITY) which identify unique record.

    is it right structure for creating index

    please give me suggestion

    thanks in advance

    Debasis

    Why does your vendor table have both a PKID and a VendorID?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • ChrisM@home (10/15/2012)


    deba_20032004 (10/15/2012)


    Dear Sir,

    I am in great trouble, my problem is I have a vendor Table

    which consist of some fields. I explaining the structure below

    Table<Vendor>

    --------------

    fields name

    -----------

    PKID int

    VENDORID int

    VENDORNAME varchar (50)

    ADDRESS varchar(50)

    CITY varchar(15)

    I have set Primary key on PKID (cluster index)

    I have set non cluster index on (VENDORID,VENDORNAME/ADDRESS) FIELDS

    now I want to set superkey on (VENDORID+ADDRESS+CITY) which identify unique record.

    is it right structure for creating index

    please give me suggestion

    thanks in advance

    Debasis

    Why does your vendor table have both a PKID and a VendorID?

    Maybe he wants to be able to change the VendorID at some future time?


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • ...

    now I want to set superkey on (VENDORID+ADDRESS+CITY) which identify unique record.

    ...

    Why three of them? Are you saying that VENDORID in your VENDOR table is not unique by itself?

    Or, you want to say that the same Vendor can have different addresses or at the same address you may hold multiple vendors? If so, you better create separate Address and VendorAddress tables to this data in RDBMS way. Address table will have AddressId and address details and VendorAddress will have VendorId and AddressId as a composite PK?

    Or, at least, just have separate VendorAddress table to store multiple vendor addresses in your way. Still, it will be way better than storing multiple records of the same vendor in Vendor table...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

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