March 14, 2013 at 2:41 pm
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
March 14, 2013 at 3:01 pm
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/
March 14, 2013 at 4:16 pm
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
March 14, 2013 at 9:12 pm
asita (3/14/2013)
Thank you Sean Langeso 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
Change is inevitable... Change for the better is not.
March 14, 2013 at 11:31 pm
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
March 15, 2013 at 6:07 am
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.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply