Is it possible to write to a database table using a transaction
without locking it?
Depends on what you mean by "it"? locks can be at different resource level meaning: row, page, table, non clustered index pages etc.
If you mean all of the above than the answer is no. At the same time you can avoid locks on some of the resources depending on the scope of your transaction and how many records you are updating.
I suggest you read this article :
Why do we need UPDATE Locks in SQL Server? by Klaus Aschenbrenner
Now let's look at an example using adventureworks database. To simulate what I am doing you can download this database from here.
--Making sure we are only updating one row
SELECT COUNT(0) FROM [Production].[Product]
SET [Name]='ML Crankarm_modified'
Since we are using
BEGIN TRAN (explicit transaction) we can check what locks this session is holding.
Looking at these locks and lock compatibility chart you should be able to figure out what select statements you can run and which one will get blocked. Keep in mind it will also be dictated by your transaction isolation level.
For example you have Intent Exclusive lock on object id 482100758 which is production.product table itself and this lock is not compatible with Shared lock. Therefore you cannot select all records from this table. But if you want to select one or more records that does not have locks incompatible with Shared lock you should be able to select data.