Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

create a table with two primary keys. Expand / Collapse
Author
Message
Posted Thursday, January 30, 2014 7:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 14, 2014 11:32 PM
Points: 8, Visits: 57
As per the requirement, it is asked to create a table with two primary keys. How can we implement the same?
Post #1536320
Posted Thursday, January 30, 2014 7:08 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053
A table cannot have two primary keys. Sure the requirement isn't for a single primary key consisting of two columns?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1536321
Posted Thursday, January 30, 2014 7:20 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 14, 2014 11:32 PM
Points: 8, Visits: 57
it is really interesting to hear. In a table, two prmary keys.
but this is a question which i got for an interview

i had options too.

as per the requirement, it is asked to create a table with two primary keys. how can we implement the same
(composite Primary key /
One primary key and one Unique key /
one primary key and unique key with NOT NULL constraint /
None of the above)

Thanks for the immediate response.
Post #1536337
Posted Thursday, January 30, 2014 7:29 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:05 PM
Points: 13,320, Visits: 12,804
Ryan George (1/30/2014)
it is really interesting to hear. In a table, two prmary keys.
but this is a question which i got for an interview

i had options too.

as per the requirement, it is asked to create a table with two primary keys. how can we implement the same
(composite Primary key /
One primary key and one Unique key /
one primary key and unique key with NOT NULL constraint /
None of the above)

Thanks for the immediate response.


So what do you think? We are not here to provide answers for interview questions so you can get a job that you are not qualified for.


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1536343
Posted Thursday, January 30, 2014 9:20 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:44 PM
Points: 4,041, Visits: 9,188
I'd say it depends on what you need because a table can't have 2 primary keys by definition. It's not about SQL Server, it's about relational theory.


Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1536413
Posted Thursday, January 30, 2014 10:40 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053
Ryan George (1/30/2014)
as per the requirement, it is asked to create a table with two primary keys. how can we implement the same


At the risk of sounding like an echo...
A table cannot have two primary keys.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1536467
Posted Thursday, January 30, 2014 5:12 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 35,768, Visits: 32,431
Ryan George (1/30/2014)
it is really interesting to hear. In a table, two prmary keys.
but this is a question which i got for an interview

i had options too.

as per the requirement, it is asked to create a table with two primary keys. how can we implement the same
(composite Primary key /
One primary key and one Unique key /
one primary key and unique key with NOT NULL constraint /
None of the above)

Thanks for the immediate response.


I feel your pain and I hate written questions like that and that's why I'd never be able to pass a test. I do, however, love such questions in an interview because they give me the chance to shine.

By definition and by design and as the others have stated, you cannot have two Primary Keys on a table. If you try to create a second real Primary Key on a table, it will give you an error (as the others have already stated).

That, not withstanding, I frequently do have the need to have a Primary Key and another key that could be used as a primary key on many of my tables and that answer is one of the 3 other answers on the list of possibilities you provided. So, now we have to guess... did the person that wrote the question understand that there truly can be one and only one primary key and he just wrote a question trying to trick you or is he someone that thinks that other kind of key is considered to be a Primary Key? Or is it a test of your interpretive capabilites to see if you understand that a lot of people don't know you can only have one real Primary Key on a table and what you would do about it if asked such a thing in real life?

If it's a written test that a human would review, I'd give the obvious answer that you can only have one and only one Primary Key for a table but I'd also write a small paragraph that you can also have a ALTERNATE KEY that could be used as a Primary Key if there wasn't one already and then I would identify which answer that one was.

If it's a test to be graded by machine, I'd go with the technically correct answer and argue it to the max if I got it wrong.

If it's a question during an interview, then it's "discussion time" where you'd explain all about PKs, AKs, and their relationship with FKs. That's what interviewers look for when they ask questions. Do you know the subject well enough to spontaneously add facts, uses, and methods or are you just "book learned".

Remember, requirements in real life are rarely technically correct and THAT might be what they were actually looking for. A lot of people don't understand that "Before you can think outside the box, you must first realize... YOU'RE IN A BOX!"


--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1536601
Posted Friday, January 31, 2014 12:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 14, 2014 11:32 PM
Points: 8, Visits: 57

So what do you think? We are not here to provide answers for interview questions so you can get a job that you are not qualified for.



Dear Mr. Lange,

if you dont know the answer, just shut up and search some other threads. dont poke your nose into this. I will ask questions which I ve doubt. Please dont reply/make any quotes if you have no clarity in the answer. And this is not the right way to handle this.

Be a Professional, Man..!!

Cheers.
Post #1536656
Posted Friday, January 31, 2014 12:36 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053
Ryan George (1/31/2014)

So what do you think? We are not here to provide answers for interview questions so you can get a job that you are not qualified for.



Dear Mr. Lange,

if you dont know the answer, just shut up and search some other threads. dont poke your nose into this. I will ask questions which I ve doubt. Please dont reply/make any quotes if you have no clarity in the answer. And this is not the right way to handle this.


Wow, just...

I can tell you Sean knows perfectly well the answer to the question. We however don't tend to like interview questions here, especially when they don't appear to be accompanied by any research (google, books online, etc). I've interviewed enough people who didn't have a clue and appeared to have just memorised answers.

Be a Professional, Man..!!


Good idea. Maybe take your own advice? Would you tell someone, someone that that you've never met and that you asked for free advice from, to their face to shut up because you didn't like their advice?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1536657
Posted Friday, January 31, 2014 2:09 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, December 12, 2014 7:23 AM
Points: 2,128, Visits: 1,487
GilaMonster (1/31/2014)
Ryan George (1/31/2014)

[quote]Be a Professional, Man..!!


Good idea. Maybe take your own advice? Would you tell someone that you've never met and that you asked for free advice from to their face to shut up because you didn't like their advice?

+1

@Ryan George: you are fairly new to the Forums and perhaps Sean could have been a little kinder, but there's no excuse for your response.

Some of the most knowledgeable and respected people in the SQL Server community (I'm not including myself in that category!) post on these forums and if you want their help in future, I suggest adjusting the tone of your posts.

Hopefully just a one-off eh?

Lempster
Post #1536670
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse