February 8, 2008 at 9:10 am
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
February 8, 2008 at 1:02 pm
No, it won't. SQL Server stores index information of each table separately.
SQL DBA.
February 8, 2008 at 1:44 pm
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[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgFebruary 8, 2008 at 1:54 pm
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
February 8, 2008 at 2:03 pm
Dave,
You are indeed getting it wrong.:hehe:
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[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgFebruary 8, 2008 at 2:08 pm
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
February 8, 2008 at 2:11 pm
doh... i've always called them Indexes, or IDs, "note to self - call them identities"
sorry all, my bad..
thanks
Dave
February 8, 2008 at 7:29 pm
"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
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply