Jess31
asked on
SQL / Table Lock?
Using sql server 2012.
I have a table that is used for only one purpose - to import its data. When I do this I want to lock this table so that it is not readable by anyone else. How can I do this?
I have a table that is used for only one purpose - to import its data. When I do this I want to lock this table so that it is not readable by anyone else. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
why not just put the database in "single user" mode? Here is a page to show how: https://technet.microsoft.com/en-us/library/ms345598(v=sql.110).aspx
If it's only used to import data, why do you want to lock it?
Also, if you don't want nobody to access it just don't provide them the necessary permissions to do so.
Also, if you don't want nobody to access it just don't provide them the necessary permissions to do so.
ASKER
Vitor,
Cause I have a function that checks this table for new data to import. This function runs every 15 minutes. And it runs from any computer running the app (could be 1 to 6). So I don't want two of them to try to import at the same time. There may be other ways to accomplish this but I thought the simplest would be to just lock this table.
Cause I have a function that checks this table for new data to import. This function runs every 15 minutes. And it runs from any computer running the app (could be 1 to 6). So I don't want two of them to try to import at the same time. There may be other ways to accomplish this but I thought the simplest would be to just lock this table.
How are you importing? You can check in the importing task if there's already any other process running so you can immediately send a message informing so and abort the import process.
Also, mind that SQL Server engine always lock a table during INSERT operations.
Also, mind that SQL Server engine always lock a table during INSERT operations.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.