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

Reindexing.. Expand / Collapse
Author
Message
Posted Friday, February 8, 2008 9:10 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 19, 2014 9:19 AM
Points: 81, Visits: 285

if i have a table ( call it tableA) and a second table ( call it tableB)

TableA has these fields
ID, Int, Key
FirstName, nvarchar(50)
LastName, nvarchar(50)
Address, nvarchar(250)

TableB has these fields
ID, Int, Key
TableAID, int,
AccountNo, nvarchar(50)
SortCode, nvarchar(50)
Bank, nvarchar(250)
etc

the two tables are not joined in a relationship.
If I reindex tableA, it will mess up all the indexes relating to table B

or did i missing something?

thanks
Dave
Post #453315
Posted Friday, February 8, 2008 1:02 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: Thursday, July 17, 2014 10:56 AM
Points: 3,924, Visits: 1,607
No, it won't. SQL Server stores index information of each table separately.

SQL DBA.
Post #453425
Posted Friday, February 8, 2008 1:44 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, September 13, 2014 7:14 AM
Points: 2,717, Visits: 3,849
And indexes are "pointers" to the physical location of the data. Think of them as floating on another layer or more appropriately as the index in the back of a book. If you move chapters/pages around the index entry for "Chapter 2" is still pointing to chapter 2 even if you've added 10 pages to chapter one. SQL Server will handle those changes on it's own. And like sanjay said, each "book" or table's indexes are managed seperately. So if table A refers to table B's chapter 2, it doesn't matter to table A where that physically is because it points to the index "Chapter 2" and not the data itself.



I may have rambelled on here, but I hope it makes sense.


______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Post #453460
Posted Friday, February 8, 2008 1:54 PM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 19, 2014 9:19 AM
Points: 81, Visits: 285
thanks for the replies guys.

urm.. yes and no, i think??

example. ( data in the tables)

tableA
ID, Name, address1, Address2
1, dave, somestreet, hull
3, frank, anotherstreet, leeds
4, john, yetanotherstreet, scunthorpe

tableB
ID, TableAID, AccountNo, SortCode, Amount,

1, 1, 00000001, 123456, 100
2, 3, 00000002, 123456, 100
3, 4 00000003, 123456, 100


if i re-index tableA so the new indexes are 1,2 and 3 instead of 1, 3 and 4
they wouldn't relate to tableB anymore. making them wrongly related tables?

Am i getting it all wrong? are there other SQL indexes other then the ones i see on the tables?

thanks
Dave
Post #453466
Posted Friday, February 8, 2008 2:03 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, September 13, 2014 7:14 AM
Points: 2,717, Visits: 3,849
Dave,

You are indeed getting it wrong.

You're confusing Foreign Keys with Indexes.

Read up on BOL on these topics and ask more questions after that.


______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Post #453471
Posted Friday, February 8, 2008 2:08 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
Aha! You're using the wrong word. The word you want is "identities", not "indexes". ("Indexes" is probably the right word in some other context, but in SQL, it's not.)

Yes, if you change the identity values in TableA, that will mess up TableB. You can handle that by adding a foreign key constraint to TableB:

alter TableB
add constraint FK_TableA foreign key (TableAID) references dbo.TableA(ID) on update cascade

Then, if you update TableA's ID, it will also update TableB.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #453474
Posted Friday, February 8, 2008 2:11 PM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 19, 2014 9:19 AM
Points: 81, Visits: 285
doh... i've always called them Indexes, or IDs, "note to self - call them identities"

sorry all, my bad..

thanks
Dave
Post #453477
Posted Friday, February 8, 2008 7:29 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Friday, June 27, 2014 12:43 PM
Points: 15,444, Visits: 9,596
"IDs" is a valid name for them. Same as "identities".

"Indexes", on the other hand, are a means of storing parts of a table in a separate structure, to speed up looking up the data from the table. (That's an oversimplification, but it goes in the right direction.) Just like the index of a book, really.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #453551
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse