What needs to consider when adding a password to the table

  • Hi There,

    Could you please help me out, i have table with 9 columns and about a million rows,

    i need to add primary key, so what things do i need to consider here,

    what if my table has no unique column / columns(composite), wat can do in this situation

    adding a id field (just 1 to .... so on) and then making this pk, does makes any sense?

    could you please help me out here

    Thanks a ton in advance

    dhani

  • Yes if there is no natural key you should add something like an identity column and make that your primary key.

    _______________________________________________________________

    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/

  • Thank you Sean Lange

    so by adding like this does help any way data retrival,

    also one more doubt is, in this table (where i want to add primary key),

    in the procedue (runs daily) loads data to the above table (several updates/deletes/inserts to this table)

    does having pk at table level will be help full? or in the proc itself first remove pk then do several actions (DML) then add pk at end does better?

    which one do you suggest

    please help me...

    thanks

    dhanvi

  • asita (3/14/2013)


    Thank you Sean Lange

    so by adding like this does help any way data retrival,

    also one more doubt is, in this table (where i want to add primary key),

    in the procedue (runs daily) loads data to the above table (several updates/deletes/inserts to this table)

    does having pk at table level will be help full? or in the proc itself first remove pk then do several actions (DML) then add pk at end does better?

    which one do you suggest

    please help me...

    thanks

    dhanvi

    What is your join criteria for the updates and deletes?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • hi jeff,

    thank you,

    the criteria is mainly on account number, which is part of or primary key,

    please suggest to have pk at table level rather every time remove pk before proc executes then add it at the end of proc execution?

    thank you

    dhanvi

  • please suggest to have pk at table level

    I guess you have no choice here. PK can only be set "at table level"

    ...every time remove pk before proc executes then add it at the end of proc execution?

    That would be worse possible design. PK shouldn't be dropped and recreated in order to run any stored proc (eg. the one which populates table.)

    If you worry about data which potentially will not load due to duplicate values in the PK column, use staging table where it's not PK, validate and then load only valid data into your final destination 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 6 posts - 1 through 5 (of 5 total)

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