SQL Server Lock Record or Multiple Records

Posted on 2008-11-14
Last Modified: 2012-05-05
I want to lock a single record in a specified table of my Database.
I want to excecute this lock to this record when my application starts and unlock when the application shutdown.
Question by:carmas123
    LVL 36

    Expert Comment

    by:Geert Gruwez
    why do you want to lock a record ?
    locking of records is only done when you need to modify the data in that record

    lets say you lock a record and the database on some server fails over to another database
    your lock would be useless ...

    care to explaing what you actually want ?
    LVL 15

    Accepted Solution

    You could query the single record on load and then close the query when you close the app

    select *
    from your_table with (rowlock)
    where id = x

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now