Connecting Tech Pros Worldwide Help | Site Map

Which implementation will give faster result (Table design to Joins)

Newbie
 
Join Date: Jan 2007
Posts: 19
#1: Feb 26 '07
I have two tables Users and UserLogin. Here i will use two methods of table design. and which query will return me the result more fast.
The table size will be large that it may contain records in lakhs.

Method 1:
Tables:
Users ( UserID varchar(20) primary key, PassWord varchar(20))
UsersLogin(UserID varchar(20),LoginDate DateTime)
Query:
Select Users.UserID,UsersLogin.LoginDate
from Users U inner join UsersLogin UL
on Users.UserID = UsersLogin.UserID
Method 2:
Tables:
Users ( SysUserID Integer primary key,UserID varchar(20), PassWord varchar(20))
UsersLogin(SysUserID Integer, LoginDate DateTime)
Query:
Select Users.UserID,UsersLogin.LoginDate
from Users U inner join UsersLogin UL
on Users.SysUserID = UsersLogin.SysUserID
Here for the seccond method i made SysUserID additional which will be a system generated ID, and for joins which will give better performance.
dorinbogdan's Avatar
Expert
 
Join Date: Feb 2007
Posts: 822
#2: Feb 26 '07

re: Which implementation will give faster result (Table design to Joins)


The second option could be better, but I'm not sure if would show too much difference. Regulary, the SQL engine is always optimizing the queries before executing.
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#3: Feb 26 '07

re: Which implementation will give faster result (Table design to Joins)


You could try taking a look at Query Analyzer's "Estimated Execution Plan" option. Highlight a query, go to the Tools menu, and select "Display Estimated Execution Plan."
Reply