MSSQL Search Multiple Tables Efficiently?

Discussion in 'Databases' started by scottlpool2003, Apr 23, 2013.

  1. #1
    I need a way to search multiple tables while minimizing process time.

    The database is quite small at the moment but will grow large over time. The query will be integrated into a search by a user on a website.

    Would it be best to do a stored procedure or just a direct query?
     
    scottlpool2003, Apr 23, 2013 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Are the tables associated with eachother via a common id/column? How many table do you need to search at the same time?
     
    jestep, Apr 23, 2013 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    The tables are associated, and I have 3.

    Do you think it would be okay searching 8 columns at the same time?
     
    scottlpool2003, Apr 23, 2013 IP
  4. funkseo

    funkseo Greenhorn

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Stored procedures are better then query because stored procedures compile on SQL Server side only when you change but queries compile every execution. So Stored procedures are faster.

    There are several things you need to be careful.
    1. There should be one primary key on each table
    2. There should be key relation between tables, you should join 2 tables with primary key and foreign key. For a better explanation, if you write your table DDL script(I mean create table table1 bla bla script) we can help better.
    3. 8 columns won't be a problem if each column content size is small and total length of a table data smaller then 8192 bytes.
     
    funkseo, Apr 24, 2013 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #5
    With stored procedures though, would that not be a major drain on resources if the database grows considerably large?
     
    scottlpool2003, Apr 24, 2013 IP
  6. funkseo

    funkseo Greenhorn

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    If you create good indexes, it won't be a problem for million rows.
    I have worked very big tables(bank systems) and if you make a good database and query optimization, it won't be a problem.
     
    funkseo, Apr 24, 2013 IP