0

I want to INSERT into one tables but prevent INSERTING to another one. It is possible to LOCK for example table a for INSERTING, INSERT to table b and then UNLOCK table a?

TABLOCK can lock only the table I am INSERTING in.

Thanks

Martin Pilch

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Martin Pilch
  • 3,245
  • 3
  • 38
  • 61
  • Why do you need to lock the other table? That might affect the best solution for your problem. – Tom H Jun 25 '10 at 14:11

1 Answers1

1

SQL Server does not allow locking objects like you would do semaphors. Also, locking a table will not make it read-only; it will make it locked out for everybody.

You can place a lock by using a table hint such as SELECT * FROM MyTable WITH (LOCKNAME) but that is not a good programming practice.

Raj More
  • 47,048
  • 33
  • 131
  • 198
  • Thanks, maybe if it will be necessary to do it, I will create table with flag, setting this flag when inserting and checking it when inserting to another table. – Martin Pilch Jun 25 '10 at 14:02