Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Do I use an index in this situation?

Author  Topic 

ned456
Starting Member

2 Posts

Posted - 2008-06-01 : 16:31:23
Hi everyone -

I am relatively new to this and trying to make my database as efficient as possible.

Here is the situation. In my database, there are multiple "stocks" that each have a "pricing history". When something happens that changes the price of the stock, an entry containing information about the time the change occured, who changed it, etc. is added.

I have many stocks. The information of these stocks is independant in the sense that I never really need to grab/compare information about two stocks at once. I only look at one stock at a time.

So, do I set up a "pricing history" table for every single stock (pricinghist1,pricinghist2,etc.)? Or do I set up one "pricing history" table it and index the table by stock number?

Are these equivilant? Is one more efficient than the other?

Thanks!
N

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-06-01 : 18:00:39
definitely use one table for all stocks, not one table per stock. index the stockid column and create a FK back to the main stock table (assuming you have one).

if you find you need to add tables to your database in the normal course of operation, that is a good indicator of a bad design.


elsasoft.org
Go to Top of Page

ned456
Starting Member

2 Posts

Posted - 2008-06-01 : 20:30:22
Hi jezemine -

Thanks for the reply...that was my suspicion.

One question - what is "FK" and what is it used for?

That question probably marks me as a true newbie.


Thanks again,
N
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-02 : 00:39:26
quote:
Originally posted by ned456

Hi jezemine -

Thanks for the reply...that was my suspicion.

One question - what is "FK" and what is it used for?

That question probably marks me as a true newbie.


Thanks again,
N



FK is abbreviation for foreign key constraint. Its a way of enforcing referential integrity between two tables. To make sure one field of a table contains only values that correspond to another table field, we define a foreign key on our table referring to source table. Whenever we are performing insert/updation of value in this field, the constraint ensures the value inserted/updated is a valid value existing within the source table field. Suggest you to go through explanation of Foreign key in books online.

[url]http://msdn.microsoft.com/en-us/library/ms175464.aspx[/url]
Go to Top of Page
   

- Advertisement -