Hi Good Morning,
I have a small Doubt in sql server. i am using a stored procedure to get Result in the form of tables
in that procedure i used just select queries
in each Query i am joining 5 tables .
when the procedure was executed it was showing result
But here the problem is it was taking time too much
Please provide me Solution to reduce the execute time of stored procedure.
Loading
Pradip PandeyPosted Feb 1, 2013, 2:56 AM
TableAId of TableA, TableAId & TableBId of TableB, TableAId, TableBId, TableCId of TableC and
TableAId, TableBId, TableCId,TableDId of TableD. Create proper primary key constraint on each table and then foreign key constraint relationship between the tables.
Hope it will help.
vinay kumarPosted Feb 1, 2013, 1:19 AM
HERE i changed the table names and every table contains Unique id
CREATE TABLE [dbo].[TableA](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[TableAId] [varchar](50) NULL,
[TableA] [varchar](50) NULL,
)
CREATE TABLE [dbo].[TableB](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[TableAId] [varchar](50) NULL,
[TableBId] [varchar](50) NULL,
[TableB] [varchar](300) NULL,
)
CREATE TABLE [dbo].[TableC](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[TableAId] [varchar](50) NULL,
[TableBId] [varchar](50) NULL,
[TableCId] [varchar](50) NULL,
[TableC] [varchar](max) NULL,
[Entrydate] [smalldatetime] NULL,
)
CREATE TABLE [dbo].[TableD](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[TableAId] [varchar](50) NULL,
[TableBId] [varchar](50) NULL,
[TableCId] [varchar](50) NULL,
[TableDId] [varchar](50) NULL,
[Image] [varbinary](max) NULL,
)
here in stored procedure i write this type of Query
select A.TableAId,A.TableA,B.TableBId,B.TableB,C.TableCId, C.TableC,D.[TableDId],D.Image,C.Entrydate
from
TableA A inner join TableB B on A.TableAId=B.TableAId
inner join TableC C on B.TableBId=C.TableBId
inner join [TableD] D on C.TableCId=D.TableCId WHERE A.TableAId='10000'
this is for just practise
i want to know how can reduce the time of execution
Pradip PandeyPosted Jan 31, 2013, 11:32 AM
Hope it will help.
vinay kumarPosted Jan 31, 2013, 5:53 AM
Pradip PandeyPosted Jan 31, 2013, 5:24 AM
If there is no any constraints defined on the table, define it. Also check data type of the column on which any constraint is defined. Similarly define indexes on the column of the table.
Try to minimize your table join by using subquery. If join is must, then check the relationship between the tables.
Hope it will help.