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

confusion in setting up superkey Expand / Collapse
Author
Message
Posted Monday, October 15, 2012 7:08 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, March 31, 2014 12:28 PM
Points: 50, 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
Post #1372714
Posted Monday, October 15, 2012 10:20 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Sunday, November 23, 2014 11:23 PM
Points: 1,281, Visits: 1,761
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.
Post #1372808
Posted Monday, October 15, 2012 10:23 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 3:12 AM
Points: 1,037, Visits: 6,959
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
Post #1372809
Posted Monday, October 15, 2012 7:05 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: 2 days ago @ 4:53 AM
Points: 3,422, Visits: 5,368
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!
Post #1373006
Posted Tuesday, October 16, 2012 5:09 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 8:23 AM
Points: 2,873, Visits: 5,189

...
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1373141
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse