Hello,
I am trying to create multiple cursors and update 2 separate tables. But the
data tables seem to be locking after I run them. Is my logic off? My code is
below -
set xact_abort on
declare @.user_id int, @.topic_name varchar(20), @.key_seq_num int
declare GetUserID cursor for
select [user_id] from users where [user_id] not in (select [user_id] from
userdata)
open GetUserID
fetch next from GetUserID into @.user_id
while @.@.fetch_status = 0
begin
begin tran
--new cursor
declare GetUserData cursor for
select topic_name from userdata where [user_id] = 327
open GetUserData
fetch next from GetUserData into @.topic_name
while @.@.fetch_status = 0
begin
begin tran
--new cursor
declare GetNextID cursor for
select key_seq_num from nextkey where key_name = 'userdata_user_data_id'
open GetNextID
fetch next from GetNextID into @.key_seq_num
while @.@.fetch_status = 0
begin
begin tran
insert into UserData(user_data_id, [user_id], topic_name, update_date,
update_user, create_date, create_user)
select @.key_seq_num, @.user_id, @.topic_name, getdate(), 'Default',
getdate(), 'Default'
update nextkey set key_seq_num = @.key_seq_num + 1
from nextkey where key_name = 'userdata_user_data_id'
commit tran
print @.key_seq_num
fetch next from GetNextID into @.key_seq_num
end
close GetNextID
deallocate GetNextID
fetch next from GetUserData into @.topic_name
end
close GetUserData
deallocate GetUserData
fetch next from GetUserID into @.user_id
end
close GetUserID
deallocate GetUserIDAnil,
Can you explain what are you trying to accomplish?
AMB
"Anil" wrote:
> Hello,
> I am trying to create multiple cursors and update 2 separate tables. But t
he
> data tables seem to be locking after I run them. Is my logic off? My code
is
> below -
> set xact_abort on
> declare @.user_id int, @.topic_name varchar(20), @.key_seq_num int
> declare GetUserID cursor for
> select [user_id] from users where [user_id] not in (select [user_id] from
> userdata)
> open GetUserID
> fetch next from GetUserID into @.user_id
> while @.@.fetch_status = 0
> begin
> begin tran
> --new cursor
> declare GetUserData cursor for
> select topic_name from userdata where [user_id] = 327
> open GetUserData
> fetch next from GetUserData into @.topic_name
> while @.@.fetch_status = 0
> begin
> begin tran
> --new cursor
> declare GetNextID cursor for
> select key_seq_num from nextkey where key_name = 'userdata_user_data_id'
> open GetNextID
> fetch next from GetNextID into @.key_seq_num
> while @.@.fetch_status = 0
> begin
> begin tran
> insert into UserData(user_data_id, [user_id], topic_name, update_date,
> update_user, create_date, create_user)
> select @.key_seq_num, @.user_id, @.topic_name, getdate(), 'Default',
> getdate(), 'Default'
> update nextkey set key_seq_num = @.key_seq_num + 1
> from nextkey where key_name = 'userdata_user_data_id'
> commit tran
> print @.key_seq_num
> fetch next from GetNextID into @.key_seq_num
> end
> close GetNextID
> deallocate GetNextID
> fetch next from GetUserData into @.topic_name
> end
> close GetUserData
> deallocate GetUserData
> fetch next from GetUserID into @.user_id
> end
> close GetUserID
> deallocate GetUserID|||I am trying to take all the user id's from cursor 1, some value from cursor
2
and 3 and update them into a table. Cursor 3 has an id that needs to be
incremented each time as it is not an auto number. The way I have laid out m
y
cursors, is that the correct way?
Thanks.
Anil
"Alejandro Mesa" wrote:
> Anil,
> Can you explain what are you trying to accomplish?
>
> AMB
>
> "Anil" wrote:
>|||Anil,
Can you explain it without referencing the cursors?
AMB
"Anil" wrote:
> I am trying to take all the user id's from cursor 1, some value from curso
r 2
> and 3 and update them into a table. Cursor 3 has an id that needs to be
> incremented each time as it is not an auto number. The way I have laid out
my
> cursors, is that the correct way?
> Thanks.
> Anil
> "Alejandro Mesa" wrote:
>|||Please provide DDL and sample data.
http://www.aspfaq.com/etiquette.asp?id=5006
AMB
"Alejandro Mesa" wrote:
> Anil,
> Can you explain it without referencing the cursors?
>
> AMB
>
> "Anil" wrote:
>|||Is the syntax correct for multiple cursors? Is it possible to do what I am
trying to do with cursors?
"Alejandro Mesa" wrote:
> Anil,
> Can you explain what are you trying to accomplish?
>
> AMB
>
> "Anil" wrote:
>|||Is the syntax correct? Is it possible to do what I am trying to do?
"Alejandro Mesa" wrote:
> Anil,
> Can you explain what are you trying to accomplish?
>
> AMB
>
> "Anil" wrote:
>|||Hi Anil,
Looks like the tables which you are accessing is getting locked since you do
all your stuff within a transaction.
You can do 2 things to see if the issue is happening because of a lock
1. Remove all transaction (begin/commit tran) and see if your code actually
works.
2. If your code works after step 1 then use WITH (NOLOCK) clause in your
select statements.
Regards,
Joe.
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:47D3D1AF-4E14-4C0B-80B9-66ADCCF91254@.microsoft.com...
> Please provide DDL and sample data.
> http://www.aspfaq.com/etiquette.asp?id=5006
>
> AMB
> "Alejandro Mesa" wrote:
>
cursor 2
be
out my
tables. But the
My code is
[user_id] from
'userdata_user_data_id'
update_date,|||Hey Joe,
Thanks for the help. Worked like a charm!!
Anil
"Joe" wrote:
> Hi Anil,
> Looks like the tables which you are accessing is getting locked since you
do
> all your stuff within a transaction.
> You can do 2 things to see if the issue is happening because of a lock
> 1. Remove all transaction (begin/commit tran) and see if your code actuall
y
> works.
> 2. If your code works after step 1 then use WITH (NOLOCK) clause in your
> select statements.
>
> Regards,
> Joe.
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in messag
e
> news:47D3D1AF-4E14-4C0B-80B9-66ADCCF91254@.microsoft.com...
> cursor 2
> be
> out my
> tables. But the
> My code is
> [user_id] from
> 'userdata_user_data_id'
> update_date,
>
>|||Hey Joe,
Thanks for the help. Worked like a charm!!
Anil
"Joe" wrote:
> Hi Anil,
> Looks like the tables which you are accessing is getting locked since you
do
> all your stuff within a transaction.
> You can do 2 things to see if the issue is happening because of a lock
> 1. Remove all transaction (begin/commit tran) and see if your code actuall
y
> works.
> 2. If your code works after step 1 then use WITH (NOLOCK) clause in your
> select statements.
>
> Regards,
> Joe.
>
> "Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in messag
e
> news:47D3D1AF-4E14-4C0B-80B9-66ADCCF91254@.microsoft.com...
> cursor 2
> be
> out my
> tables. But the
> My code is
> [user_id] from
> 'userdata_user_data_id'
> update_date,
>
>sql
Showing posts with label thedata. Show all posts
Showing posts with label thedata. Show all posts
Friday, March 23, 2012
Wednesday, March 7, 2012
Multiple servers running
We have our main core processing running Oracle but uses sqlpipe to reach the
data center. We are now installing new software that uses sql as it's
database server. The problem I have is each instance looks for the same
servername. can you add multiple servernames with the sql.ini file or how
would you go about this?
Scott
"Spenbank" <Spenbank@.discussions.microsoft.com> wrote in message
news:D05AE45F-EBE7-43BA-96A3-EBEBCF73AC43@.microsoft.com...
> We have our main core processing running Oracle but uses sqlpipe to reach
the
> data center. We are now installing new software that uses sql as it's
> database server. The problem I have is each instance looks for the same
> servername. can you add multiple servernames with the sql.ini file or how
> would you go about this?
Look up INSTANCES in books online.
So you'd have something like:
SERVER\Instance1
SERVER\Instance2
etc.
Generally at least in non cluster situations I find having separate
instances not a big help for SQL Server.
> --
> Scott
|||"Greg D. Moore (Strider)" <mooregr_deleteth1s@.greenms.com> wrote in message
news:qnFtd.39078$1u.35551@.twister.nyroc.rr.com...
> "Spenbank" <Spenbank@.discussions.microsoft.com> wrote in message
> news:D05AE45F-EBE7-43BA-96A3-EBEBCF73AC43@.microsoft.com...
> the
> Look up INSTANCES in books online.
> So you'd have something like:
> SERVER\Instance1
> SERVER\Instance2
> etc.
> Generally at least in non cluster situations I find having separate
> instances not a big help for SQL Server.
>
>
Ahh, but in our hosted environment, each company can have it's own
"instance" and have their own set of security credentials that give them
access to their instance, but no one elses. =)
Rick Sawtell
MCT, MCSD, MCDBA
|||"Rick Sawtell" <quickening@.msn.com> wrote in message
news:OA4qrOU3EHA.4072@.TK2MSFTNGP10.phx.gbl...
> "Greg D. Moore (Strider)" <mooregr_deleteth1s@.greenms.com> wrote in
message[vbcol=seagreen]
> news:qnFtd.39078$1u.35551@.twister.nyroc.rr.com...
> Ahh, but in our hosted environment, each company can have it's own
> "instance" and have their own set of security credentials that give them
> access to their instance, but no one elses. =)
Hence my qualification. :-)
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>
data center. We are now installing new software that uses sql as it's
database server. The problem I have is each instance looks for the same
servername. can you add multiple servernames with the sql.ini file or how
would you go about this?
Scott
"Spenbank" <Spenbank@.discussions.microsoft.com> wrote in message
news:D05AE45F-EBE7-43BA-96A3-EBEBCF73AC43@.microsoft.com...
> We have our main core processing running Oracle but uses sqlpipe to reach
the
> data center. We are now installing new software that uses sql as it's
> database server. The problem I have is each instance looks for the same
> servername. can you add multiple servernames with the sql.ini file or how
> would you go about this?
Look up INSTANCES in books online.
So you'd have something like:
SERVER\Instance1
SERVER\Instance2
etc.
Generally at least in non cluster situations I find having separate
instances not a big help for SQL Server.
> --
> Scott
|||"Greg D. Moore (Strider)" <mooregr_deleteth1s@.greenms.com> wrote in message
news:qnFtd.39078$1u.35551@.twister.nyroc.rr.com...
> "Spenbank" <Spenbank@.discussions.microsoft.com> wrote in message
> news:D05AE45F-EBE7-43BA-96A3-EBEBCF73AC43@.microsoft.com...
> the
> Look up INSTANCES in books online.
> So you'd have something like:
> SERVER\Instance1
> SERVER\Instance2
> etc.
> Generally at least in non cluster situations I find having separate
> instances not a big help for SQL Server.
>
>
Ahh, but in our hosted environment, each company can have it's own
"instance" and have their own set of security credentials that give them
access to their instance, but no one elses. =)
Rick Sawtell
MCT, MCSD, MCDBA
|||"Rick Sawtell" <quickening@.msn.com> wrote in message
news:OA4qrOU3EHA.4072@.TK2MSFTNGP10.phx.gbl...
> "Greg D. Moore (Strider)" <mooregr_deleteth1s@.greenms.com> wrote in
message[vbcol=seagreen]
> news:qnFtd.39078$1u.35551@.twister.nyroc.rr.com...
> Ahh, but in our hosted environment, each company can have it's own
> "instance" and have their own set of security credentials that give them
> access to their instance, but no one elses. =)
Hence my qualification. :-)
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>
Subscribe to:
Posts (Atom)