How to allow multi user work on same table without any issue of interact data ?

ahmed salah 3,216 Reputation points
2022-01-08T09:38:01.067+00:00

I work on sql server 2017 I have issue
How to allow mutli user working on same table without using temp table
and without interact two user with same data
as example

user a :

exec sp_workingmultiuser 5

user b :

exec sp_workingmultiuser 10

create proc sp_workingmultiuser
@productid int
as
begin

select * into dbo.testtrade from parts.tradecodes
where productid=@productid

end

so my question if
user a
using product id 5
and
user b
using product id 10 on same time

data for user b will display for user a

so how to prevent that please ?

Developer technologies Transact-SQL
SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-01-08T11:28:01.27+00:00

    Using SELECT INTO to create a permanent table in a stored procedure in a multi-user system is an utterly bad idea, so the simple answer is: don't do that!

    If you explain in more detail what you want to achieve, we might be able to come up with some suggestions.


  2. LiHong-MSFT 10,056 Reputation points
    2022-01-10T06:12:58.057+00:00

    Hi,@ahmed salah
    Two things that puzzle me:

    1. Why not have a try on temp table (#tablename) or use variable table.
    2. Is there any error message?such as timeout,lock etc.

    Best regards,
    LiHong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.