|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
variables for table names in stored proc
i'm trying to create a stored procedure that takes 2 input parameters (taken from a querystring): a table name, and a number that needs to be checked whether it exists within that table. yes, i have different tables, one for each forum, so they will have the same structures -- i'm figuring this approach will result in faster page-load times if the tables have less in them. if everyone here tells me that having one table for all the forums will work fine, i'll just go that route, but if not, here's my procedure:
Create Procedure VerifySubjectNum (@forum_ID VARCHAR(10), @subject_num INT) As If Exists (SELECT subject_num FROM @forum_ID WHERE subject_num = @subject_num) Return 1 Else Return 0 when i try to create this, i get an error saying @forum_ID must be declared... why doesn't it work within the select for the EXISTS? |
|
#2
|
|||
|
|||
|
Use one table for all forums. If you have proper indexing it will not be any performance drawback.
|
|
#3
|
|||
|
|||
|
can you give me an example of what proper indexing would be for one table that contains 4 different forums?
|
|
#4
|
|||
|
|||
|
It depends on how the table is defined and what queries you are using. You would still need indexing if you have multiple tables.
|
|
#5
|
|||
|
|||
|
okay, so here's what i'm playing with right now...
i'm trying to use 1 table for 4 forums. each row is a single post, and its location is determined by two columns: forum_ID (a short varchar, which will be 1 of 4 possiblities) and subject_num (int, which will take on the subject number of its parent post). it also has a column post_num (int) which is an identity. queries will be used to retrieve, most importantly, a list of all subjects within a forum, and a list of all posts within a subject within a forum. so i played around with indexing/keys (which i don't know much about, admittedly), and made forum_ID a clustered key, and subject_num a regular key. i can't make either a primary key since their data will not be unique. am i on the right track? ![]() |
|
#6
|
|||
|
|||
|
Quote:
Definitely with not having multiple tables for similar data. You may benefit from having a combinded index on subject and forum instead of just subject. |
|
#7
|
|||
|
|||
|
so , keep the forum_ID clustered index, and make the index i have for subject_num also include forum_ID?
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > variables for table names in stored proc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|