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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 stored procedure help

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-21 : 08:41:52
Praveen writes "Hi,
I am using SQL server 2000. In one my of stored procedure, I am inserting records in a table which has 42 fields and data type for most of the fields are varchar. The data is taken by using JOIN on 5 tables. I am commiting transaction in loop for minimum use of tempdb. Total 1400000 records are inserting in this table. This procedure takes more than 24 hour on server which has 1 GB RAM and i processor. But it can not completes in this time also and sometimes gives error "tempdb full". But it is working fine on server which has 3GB RAM and 4 processors, it executes within 30 minutes. Whats problem?. Please help me."

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-09-21 : 10:22:25
why are you putting 1.4 million records into a temp table?

And you wonder what the difference is when you quadruple the processors and triple the RAM... really?!?


Problem: Too much work for your slower computer...
Solution: Get a more powerful 2nd computer OR Fix your stored procedure so that it runs as efficiently as possible (probably not a 1.4 mil record temp table...)

Corey
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2004-09-21 : 17:06:58
Can you use a Cursor to filter the where clause for your insert...

Thinking you may be able to do a Select Distinct from some field that would section the data into different commit points.

ie

declare @ProductID VarChar(255)

declare c1 cursor FAST_FORWARD for
select Distinct Productid From Product
open c1
fetch next from c1 into @ProductID
while @@fetch_status = 0
begin
Begin Tran
insert into CustomerProduct
select *
from Product p Inner Join Customer c On p.ProductId = c.ProductID
where p.ProductId = @ProductID

if @@error <> 0
begin
Rollback tran
raiserror('Failed to create product customer data.',16, 1)
return -1
end
Else
Begin
Commit Tran
End
fetch next from c1 into @ProductID
end
close c1
deallocate c1




Surf On Dude!
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-09-21 : 23:23:50
is it possible to use updatable views?
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2004-09-22 : 12:59:42
Could you expand on that...

Surf On Dude!
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-09-22 : 22:52:11
from BOL
quote:

Updatable Views
Microsoft SQL Server 2000 enhances the class of updatable views in two ways:

INSTEAD OF Triggers: INSTEAD OF triggers can be created on a view in order to make a view updatable. The INSTEAD OF trigger is executed instead of the data modification statement on which the trigger is defined. This trigger allows the user to specify the set of actions that need to take place in order to process the data modification statement. Thus, if an INSTEAD OF trigger exists for a view on a given data modification statement (INSERT, UPDATE, or DELETE), the corresponding view is updatable through that statement. For more information about INSTEAD OF triggers, see Designing INSTEAD OF triggers.


Partitioned Views: If the view is of a specified form called 'partitioned view,' the view is updatable, subject to certain restrictions. Partitioned views and their updatability are discussed later in this topic.
When needed, SQL Server will distinguish Local Partitioned Views as the views in which all participating tables and the view are on the same SQL Server, and Distributed Partitioned Views as the views in which at least one of the tables in the view resides on a different (remote) server.

If a view does not have INSTEAD OF triggers, or if it is not a partitioned view, then it is updatable only if the following conditions are satisfied:

The select_statement has no aggregate functions in the select list and does not contain the TOP, GROUP BY, UNION (unless the view is a partitioned view as described later in this topic), or DISTINCT clauses. Aggregate functions can be used in a subquery in the FROM clause as long as the values returned by the functions are not modified. For more information, see Aggregate Functions.


select_statement has no derived columns in the select list. Derived columns are result set columns formed by anything other than a simple column expression, such as using functions or addition or subtraction operators.


The FROM clause in the select_statement references at least one table. select_statement must have more than non-tabular expressions, which are expressions not derived from a table. For example, this view is not updatable:
CREATE VIEW NoTable AS
SELECT GETDATE() AS CurrentDate,
@@LANGUAGE AS CurrentLanguage,
CURRENT_USER AS CurrentUser

INSERT, UPDATE, and DELETE statements also must meet certain qualifications before they can reference a view that is updatable, as specified in the conditions above. UPDATE and INSERT statements can reference a view only if the view is updatable and the UPDATE or INSERT statement is written so that it modifies data in only one of the base tables referenced in the FROM clause of the view. A DELETE statement can reference an updatable view only if the view references exactly one table in its FROM clause.

Go to Top of Page

GunZ
Starting Member

29 Posts

Posted - 2004-09-23 : 00:25:39
quote:
Originally posted by AskSQLTeam

Praveen writes "Hi,
... Total 1400000 records are inserting in this table. This procedure takes more than 24 hour on server which has 1 GB RAM and i processor. But it can not completes in this time also and sometimes gives error "tempdb full". But it is working fine on server which has 3GB RAM and 4 processors, it executes within 30 minutes. Whats problem?. Please help me."



me thinks server with 1 GB RAM and i processor has less disk space than server with has 3GB RAM and 4 processors as the former compalains of "tempdb full".

But, I could be rong...

Australia.NSW.Sydney.GunZ
Go to Top of Page

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2004-09-23 : 17:50:26
Hi again...
I was the one that told you you could use a cursor... Learned something along the way and thought I would post a revised solution and try to wipe the Mud off my face.

Declare @ProjectID Char(6), @sSql as nVarChar(1000)
If Exists(Select Top 1 * from #ProjectID)
Drop Table #ProjectID

--CREATE YOUR TEMP TABLE WITH DISTINCT VALUES
--MAKE IT SMALL YOU ONLY NEED THE VALUE.

Select Distinct Project_Id Into #ProjectID From Project

While Exists(Select Top 1 * from #ProjectId)
BEGIN
--GET THE FIRST VALUE
Select Top 1 @ProjectID = Project_Id from #ProjectId
--RUN THE INSERT BASED ON A WHERE CLAUSE FROM THE MATCHING ID'S
Set @sSql =
'Select * Into ResultsTable from PL Where Project_Id = ''' + @ProjectID + ''''
Exec sp_ExecuteSql @sSql
--REMOVE THE ID FROM THE TEMP TABLE AND LOOP FOR NEXT VALUE
Set @sSql = 'Delete from #ProjectId Where Project_Id =''' + @ProjectID + ''''
Exec sp_ExecuteSql @sSql
END --while

--THANK YOU ALL FOR THE GREAT FEED BACK I SEE IN THESE FORMS


Surf On Dude!
Go to Top of Page
   

- Advertisement -