SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


confusion in setting up superkey


confusion in setting up superkey

Author
Message
deba_20032004
deba_20032004
Old Hand
Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)Old Hand (306 reputation)

Group: General Forum Members
Points: 306 Visits: 221
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
Andrew G
Andrew G
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4047 Visits: 2281
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.
ChrisM@home
ChrisM@home
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5176 Visits: 10606
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?


Low-hanging fruit picker and defender of the moggies





For better assistance in answering your questions, please read this.




Understanding and using APPLY, (I) and (II) Paul White

Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
dwain.c
dwain.c
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17723 Visits: 6431
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Eugene Elutin
Eugene Elutin
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12348 Visits: 5478

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


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search