Lock 'Childreen' Table

Hi!
I'm new in SQL and I´ve been the problem bellow:
I lock a record in one foreign table and automaticaly SQL lock the record that matches on primary table.
But this occours just in some primaries tables and not in all. I need that just the table that are of SELECT are lock. How can I do this?
Example:
** At open of the invoice:
SET ISOLATION LEVEL READ UNCOMMITTED
BEGIN TRANSACTION
SELECT * FROM INVOICE WITH (ROWLOCK UPLOCK) WHERE ( ID = 15 )
******* at the end of invoice:
INSERT INTO INVOICE ........
COMMIT TRANSACTION
END
******* The relationship are:
INVOICE <>> ITENS_INVOICE 
ITENS_INVOICE <>> PRODUCTS
CUSTOMER <>> INVOICE
VENDORS <>> INVOICE
Just the INVOICE and PRODUCTS record´s involved in Transaction are lock. ( The CUSTOMER and VENDORS are not locked for example )
But I need that just INVOICE record be locked.
Thank´s for all and sorry my English.
Igor Sane
São Paulo - Brazil

You can not lock SELECTs
If you use 
CREATE TABLE t1 (c int)
BEGIN TRAN
SELECT  top 0 * FROM t1 WITH (TABLOCK, REPEATABLEREAD) 
INSERT INTO t1 ....
In another Window users will be blocked to insert a new row into a t1 table
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Uri, did you want to become a Moderator in this forum? Please email me. It's edprice at Microsoft. Thank you!
Ed Price, Power BI & SQL Server Customer Program Manager (Blog,
Small Basic,
Wiki Ninjas,
Wiki)
Answer an interesting question?
Create a wiki article about it!

Similar Messages

  • How to see lock on table and query?

    Hi All,
    How do we see lock on table and query?
    Thanks,
    Rafi

    Yes Rafi,
    It is working fine at my end. See below:
    Opened Session 1 with scott/tiger and:
    update emp set ename='xx' where empno=7499;
    Opened Session 2 with scott/tiger and:
    update emp set ename='xx' where empno=7499;
    <<Its lock here>> This session is locked by above one.
    Opened Session 3 with sys/pw as sysdba and:
    SQL> set serveroutput on
    SQL> BEGIN
      2  dbms_output.enable(1000000);
      3  for do_loop in (select session_id, a.object_id, xidsqn, oracle_username, b.owner owner,
      4  b.object_name object_name, b.object_type object_type
      5  FROM v$locked_object a, dba_objects b
      6  WHERE xidsqn != 0
      7  and b.object_id = a.object_id)
      8  loop
      9  dbms_output.put_line('.');
    10  dbms_output.put_line('Blocking Session : '||do_loop.session_id);
    11  dbms_output.put_line('Object (Owner/Name): '||do_loop.owner||'.'||do_loop.object_name);
    12  dbms_output.put_line('Object Type : '||do_loop.object_type);
    13  for next_loop in (select sid from v$lock
    14  where id2 = do_loop.xidsqn
    15  and sid != do_loop.session_id)
    16  LOOP
    17  dbms_output.put_line('Sessions being blocked : '||next_loop.sid);
    18  end loop;
    19  end loop;
    20  END;
    21  /
    Blocking Session : 139
    Object (Owner/Name): SCOTT.EMP
    Object Type : TABLE
    Sessions being blocked : 134
    PL/SQL procedure successfully completed.HTH
    Girish Sharma

  • How can I lock a table so that a person can only enter data, not manipulate the table?

    I don't want to Lock the table as Numbers does it so perhaps locking is the wrong term. What I want to do is to lock the formatting of the table so it is possible to enter data but not possible to change the position, number of columns etc. I've been searching and all I can come up with is the regular lock function. But I still want to be able to use the cells. Just not change formatting.
    Thanks, Brad

    you cannot.  When you lock a table the whole table is locked.  I would consider segmenting the user input into a seprate, un-locked table and placing the calculations in a locked table

  • Help on locking MySQL tables (many can read, but only one can write) Java

    Hi there,
    I have a question regarding locking of tables so that only one person can write to the file, but many are able to read the files (or tables entities).
    I am not sure if I need to lock the tables in my Java code or do I lock the tables within the MySQL syntax. I'm just a little confused on the matter.
    This java code is a working prototype of inserting a customer data into the database and that works fine. I just don't know how to implement it so that only one person can update the table at a time.
    Here is the Customer.java code that I have written.
    Help would be greatly appreciated, thanks so much.
    package business;
    //~--- non-JDK imports --------------------------------------------------------
    import shared.info.CustomerInfo;
    //~--- JDK imports ------------------------------------------------------------
    import java.sql.*;
    * @author
    public class Customer {
        static Connection    con  = DBConnection.getConnection();
        private CustomerInfo info = new CustomerInfo();
        private String               customerID;
        private String               firstName;
        private String               lastName;
        private String               email;
        private String               addressID;
        private String               homePhone;
        private String               workPhone;
        private String               unitNum;
        private String               streetNum;
        private String               streetName;
        private String               city;
        private String               provinceState;
        private String               country;
        private String               zipPostalCode;
        public Customer(String id) {
            try {
                PreparedStatement pstmt = con.prepareStatement("SELECT * FROM " +
                        "Customer NATURAL JOIN Address WHERE CustomerID = ?");
                pstmt.setString(1, id);
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    customerID    = rs.getString("CustomerID");
                    firstName     = rs.getString("FirstName");
                    lastName      = rs.getString("LastName");
                    homePhone     = rs.getString("HomePhone");
                    workPhone     = rs.getString("WorkPhone");
                    email         = rs.getString("Email");
                    city          = rs.getString("City");
                    provinceState = rs.getString("ProvinceState");
                    country       = rs.getString("Country");
                    zipPostalCode = rs.getString("ZipPostalCode");
                    unitNum       = rs.getString("UnitNum");
                    streetNum     = rs.getString("StreetNum");
                    streetName    = rs.getString("StreetName");
                    addressID     = rs.getString("AddressId");
            } catch (SQLException e) {
                e.printStackTrace();
            info.setCustomerID(customerID);
            info.setFirstName(firstName);
            info.setLastName(lastName);
            info.setHomePhone(homePhone);
            info.setWorkPhone(workPhone);
            info.setEmail(email);
            info.setCity(city);
            info.setProvinceState(provinceState);
            info.setCountry(country);
            info.setZipPostalCode(zipPostalCode);
            info.setUnitNum(unitNum);
            info.setStreetNum(streetNum);
            info.setStreetName(streetName);
            info.setAddressID(addressID);
        public static void addCustomer(CustomerInfo cust) {
            try {
                int id = -1;
                PreparedStatement pstmt = con.prepareStatement("INSERT INTO Address" +
                        "(UnitNum, StreetNum, StreetName, City, ProvinceState, Country," +
                        " ZipPostalCode) VALUES(?, ?, ?, ?, ?, ?, ?)");
                pstmt.setString(1, cust.getUnitNum());
                pstmt.setString(2, cust.getStreetNum());
                pstmt.setString(3, cust.getStreetName());
                pstmt.setString(4, cust.getCity());
                pstmt.setString(5, cust.getProvinceState());
                pstmt.setString(6, cust.getCountry());
                pstmt.setString(7, cust.getZipPostalCode());
                pstmt.executeUpdate();
                ResultSet rs = pstmt.getGeneratedKeys();
                rs.next();
                id = rs.getInt(1);
                pstmt = con.prepareStatement("INSERT INTO Customer" +
                        "(FirstName, LastName, HomePhone, WorkPhone, Email, AddressID)"
                        + "VALUES(?, ?, ?, ?, ?, ?)");
                pstmt.setString(1, cust.getFirstName());
                pstmt.setString(2, cust.getLastName());
                pstmt.setString(3, cust.getHomePhone());
                pstmt.setString(4, cust.getWorkPhone());
                pstmt.setString(5, cust.getEmail());
                pstmt.setInt(6, id);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
        public void setFirstName(String newName) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET FirstName = ? WHERE CustomerID = ?");
                pstmt.setString(1, newName);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            firstName = newName;
        public void setLastName(String newName) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET LastName = ? WHERE CustomerID = ?");
                pstmt.setString(1, newName);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            lastName = newName;
        public String getFirstName() {
            return firstName;
        public String getLastName() {
            return lastName;
        public void setHomePhone(String number) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET HomePhone = ? WHERE CustomerID = ?");
                pstmt.setString(1, number);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            homePhone = number;
        public String getHomePhone() {
            return homePhone;
        public void setWorkPhone(String number) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer"
                                              + " SET WorkPhone = ? WHERE CustomerID = ?");
                pstmt.setString(1, number);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            workPhone = number;
        public String getWorkPhone() {
            return workPhone;
        public void setEmail(String email) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Customer" + " SET Email = ? WHERE CustomerID = ?");
                pstmt.setString(1, email);
                pstmt.setString(2, customerID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            this.email = email;
        public String getEmail() {
            return email;
        public void setUnitNum(String num) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET UnitNum = ? WHERE AddressId = ?");
                pstmt.setString(1, num);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            unitNum = num;
        public String getUnitNum() {
            return unitNum;
        public void setCity(String city) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET City = ? WHERE AddressId = ?");
                pstmt.setString(1, city);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            this.city = city;
        public String getCity() {
            return city;
        public void setStreetNum(String num) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address" + " SET StreetNum = ? WHERE AddressId = ?");
                pstmt.setString(1, num);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            streetNum = num;
        public String getStreetNum() {
            return streetNum;
        public void setStreetName(String name) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address"
                                              + " SET StreetName = ? WHERE AddressId = ?");
                pstmt.setString(1, name);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            streetName = name;
        public String getStreetName() {
            return streetName;
        public void setZipPostalCode(String code) {
            try {
                PreparedStatement pstmt = con.prepareStatement("UPDATE Address"
                                              + " SET ZipPostalCode = ? WHERE AddressId = ?");
                pstmt.setString(1, code);
                pstmt.setString(2, addressID);
                pstmt.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            zipPostalCode = code;
        public String getZipPostalCode() {
            return zipPostalCode;
        public CustomerInfo getInfo(){
            return info;
        static void deleteCustomer(String customerId) {
            try{
                PreparedStatement pstmt = con.prepareStatement("DELETE FROM Customer" +
                        " WHERE CustomerId = ?");
                pstmt.setString(1, customerId);
                pstmt.executeUpdate();
            }catch(SQLException e){
                e.printStackTrace();
        static void updateCustomer(CustomerInfo custInf) {
            try{
                PreparedStatement pstmt = con.prepareStatement("UPDATE customer" +
                        " SET firstName = ?, SET lastName = ?," +
                        " SET homePhone = ?, SET workPhone = ?, SET email = ?" +
                        " WHERE CustomerId = ?");
                pstmt.setString(1, custInf.getFirstName());
                pstmt.setString(2, custInf.getLastName());
                pstmt.setString(3, custInf.getHomePhone());
                pstmt.setString(4, custInf.getWorkPhone());
                pstmt.setString(5, custInf.getEmail());
                pstmt.setString(6, custInf.getCustomerID());
                pstmt.executeUpdate();
                pstmt = con.prepareStatement("UPDATE address" +
                        " SET unitNum = ?, SET StreetNum = ?, SET StreetName = ?," +
                        " SET city = ?,SET Province = ?,SET country = ?,SET ZipPostalCode = ?" +
                        " WHERE AddressId = ?");
                pstmt.setString(1, custInf.getUnitNum());
                pstmt.setString(2, custInf.getStreetNum());
                pstmt.setString(3, custInf.getStreetName());
                pstmt.setString(4, custInf.getCity());
                pstmt.setString(5, custInf.getProvinceState());
                pstmt.setString(6, custInf.getCountry());
                pstmt.setString(7, custInf.getZipPostalCode());
                pstmt.setString(8, custInf.getAddressID());
                pstmt.executeUpdate();
            }catch(SQLException e){
                e.printStackTrace();
    }In addition, here is my customer sql table.
    -- Table structure for table `customer`
    DROP TABLE IF EXISTS `customer`;
    CREATE TABLE `customer` (
    `CustomerID` mediumint(9) NOT NULL auto_increment,
    `FirstName` varchar(20) NOT NULL,
    `LastName` varchar(20) NOT NULL,
    `HomePhone` varchar(11) NOT NULL,
    `WorkPhone` varchar(11) default NULL,
    `Email` varchar(20) NOT NULL,
    `AddressID` mediumint(9) default NULL,
    PRIMARY KEY (`CustomerID`),
    KEY `AddressID` (`AddressID`),
    CONSTRAINT `customer_ibfk_1` FOREIGN KEY (`AddressID`) REFERENCES `address` (`AddressID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    -- Dumping data for table `customer`
    LOCK TABLES `customer` WRITE;
    /*!40000 ALTER TABLE `customer` DISABLE KEYS */;
    /*!40000 ALTER TABLE `customer` ENABLE KEYS */;
    UNLOCK TABLES;

    to the best of my knowledge, this is something related to the database and not the programming. If you'd want to be the only user to read and edit the table, speicify only one user with that privilege and make it password protected. User must enter the password to write to the tables.

  • Lock Object (Not locking the table)

    Hi Guys
    I have a custom table ZDRAD same like standard table DRAD with an additional 'DATE' field . ZDRAD's Key fields are same like DRAD . I have created a lock object 'EZDRAD' where I put name = 'ZDRAD' (Custom table) and mode = 'EXCLUSIVE CUMULATIVE' . Now I want to lock the table(Whole table) before modifying/Inserting/deleting the records in se38. Please check the code below and suggest me if I am passing wrong values to the lock object Function module.
    Code
    TABLES : ZDRAD.
    CALL FUNCTION 'ENQUEUE_EZDRAD'
    EXPORTING
       MODE_ZDRAD           = 'E'
       MANDT                = SY-MANDT
       DOKAR                = ' '
       DOKNR                = ' '
       DOKVR                = ' '
       DOKTL                = ' '
       DOKOB                = ' '
       OBZAE                = 0
       OBJKY                = ' '
       X_DOKAR              = ' '
       X_DOKNR              = ' '
       X_DOKVR              = ' '
       X_DOKTL              = ' '
       X_DOKOB              = ' '
       X_OBZAE              = ' '
       X_OBJKY              = ' '
       _SCOPE               = '2'
       _WAIT                = 'X'
       _COLLECT             = ' '
    EXCEPTIONS
       FOREIGN_LOCK         = 1
       SYSTEM_FAILURE       = 2
       OTHERS               = 3
    *IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    IF SY-SUBRC = 0.
    ZDRAD table is locked.
        P_L_LOCK_STAT = 'X'.
        EXIT.
      ELSE.
    ZDRAD table is not locked
        CLEAR P_L_LOCK_STAT .
      ENDIF.

    Hi Kanthimathi
    That is numeric field . Please suggest me how can i check the lock.

  • An error occurred in lock management when attempting to set a lock on table

    Hi All,
    I am getting the error 'An error occurred in lock management when attempting to set a lock on table SWWWIHEAD.'
    Sometimes the workitem is not created by the Workflow due to above error & this happens rarely but keeps coming.
    cany anyone guide or help me how to correct this problem.Is it happening due to my custom code making locks on the above table?
    Thanks in advance.
    Pls do reply

    I think you should not use any code to lock the table SWWWIHEAD.  Please let us know why you are writing code to put lock on this table.
    Thanks
    Arghadip

  • Is there any function module to lock t024 table

    is there lock object for t024 table?otherwise any fm for locking t024 table?

    Hi Naren,
    <b>Good ... check out the following documentation
    Lock objects are used to lock the database table while making the modifications on the database table.
    you can create your own lock objects using SE11.
    if you create lock objects on any table system will create two function modules.
    1.ENQUEUE....
    2.DEQUEUE.....
    first one is used to lock the table
    second one used to removing lock on the table.
    lock Table
    CALL FUNCTION 'ENQUEUE_E_TABLE'
    EXPORTING
    tabname = table_name
    EXCEPTIONS
    foreign_lock = 1
    system_failure = 2
    OTHERS = 3.
    Unlock Table
    CALL FUNCTION 'DEQUEUE_E_TABLE'
    EXPORTING
    tabname = table_name
    check this link :
    http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
    _SCOPE = 1: The lock is not sent to the update program. The lock is removed when the transaction is ended.
    _SCOPE = 2: The lock is sent to the update program. The update program is responsible for removing the lock. The dialog program which requested the lock no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.
    _SCOPE = 3: The lock
    Re: lock objects
    Managingin lock entries
    http://help.sap.com/saphelp_nw04/helpdata/en/37/a2e3ae344411d3acb00000e83539c3/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/7b/f9813712f7434be10000009b38f8cf/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/cb/168237d30d974be10000009b38f8cf/frameset.htm</b>
    Good Luck and thanks
    AK

  • How to lock a table in a report program

    Hi all,
         I have a requirement inwhich if i have selected one radio button  the table should locked .
       and the i need to check wether the table is locked or not by checking the condition.if locked continue else i need to stop.
    can any one help me doing this.

    Hi,
    Hope this information will be useful for you.....
    The description of an SAP lock to a table is made via the lock condition and the lock mode.
    The lock condition is a logical condition for the lines of the table to be locked. It describes the area of the table which the lock is to protect from competitive access. To avoid the administration of the lock becoming complicated, the lock condition can not be formulated as freely as the WHERE clauses:  only fully qualified key fields related by AND may appear in the condition.
    Via the lock mode you define which operations on the table are to be protected by the lock. The lock modes available are:
    Read lock (shared lock)
    protects read access to an object. The read lock allows other transactions read access but not write access to the locked area of the table.
    Write lock (exclusive lock)
    protects write access to an object. The write lock allows other transactions neither read nor write access to the locked area of the table.
    Enhanced write lock (exclusive lock without cumulation)
    works like a write lock except that the enhanced write lock also protects from further accesses from the same transaction.
    In order to be able to define SAP locks for a table, you must first create a lock object for the table via Development->Dictionary.
    If the data for an application object is distributed among several database tables, it is often necessary to be able to lock these tables simultaneously. It is therefore possible to include several tables in a lock object, althought they must be related via appropriate foreign key relationships. The tables involved in a lock object are also known as its base tables.
    Thanks
    NITESH

  • Problem related to locking the table

    Hi all,
    i am facing a problem while applying locks on the oracle table.my intention is stop the accessing of table to other users, if the table is locked by one user.
    for this i wrote the code as follows
    Class.forName("oracle.jdbc.driver.OracleDriver");       con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.2.123:1521:xe",         "root", "paridb");   con.setAutoCommit(false);             System.out.println("Successfully connected to " +           "Oracle server using TCP/IP..."); String lock="lock table report@xe in exclusive mode";-------------------------------------->1  query to lock the table Statement stmt1=con.createStatement(); stmt1.executeUpdate(lock); System.out.println("lock is applied"); Statement stmt=con.createStatement();                 for(int i=0;i<6;i++)         {         sql="insert into report values(1921682123,'device','host')";         stmt.executeUpdate(sql);         }
    after locking i inserted some data into table, after insertion i am not commiting it because if i commit,the lock will be release.next i am trying to insert data into that table from another system,acutually the data don't insert.but data is inserted. how it is happening like that ??
    in another scenario, if execute the locking query on the database directly then trying to insert into database through java application, at that time it is not giving permission to access table.
    plz guide me
    thanks&regards,
    nagaraju

    Hi! Thank you so much for your reply. Yes, I´m using ADF. I attach you the iterator´definition from the page definition:
    <iterator id="MovimientosCtbView3Iterator" RangeSize="10"
    Binds="MovimientosCtbView3" DataControl="AppModuleDataControl"/>
    If I set the RangeSize to 11, the problem is solved, but my project manager want to find out why this situation happens with RangeSize=10.
    Thank you so much and sorry for bothering you

  • How to LOCK a table in SAP?

    Hi,
    Just wondering is there a way we can lock a table in SAP?
    tcode or something?
    ex. there a tcode to lock tcodes (SM01)
    so wondering if there is a tcode or another method?
    Thanks!

    Hi,
    These are application locks not the database tables lock.
    If you use this function modules (enqeue and dequeue)
    then only it works the concept of locking.If you dont use this fms then you can directly access the table.
    If I am the developer and I dont implement the  locks then no locking concept would happen.
    Regards,
    Vamshi.

  • How to lock a table when i insert a row

    hi, friends,
    how to lock a table when i insert a row, then unlock the table

    If you want to lock the whole table so that no-one else can do DML then you go LOCK TABLE <table> IN EXCLUSIVE MODE. This lock remains in force until you commit or rollback.
    There are less powerful locking modes available, but you can look those up in the OTN online documentation.
    APC

  • DEAD LOCKS on table ARFCSSTATE

    Please help!
    Essentially the problem is that anything that updates the customer master (T/C BP) causes DEAD LOCKS on table ARFCSSTATE and the queues either slow down terrible or they hang (stop).  When one tries to delete an entry in the queue a screen dump takes place – DBIF_RSQL_SQL_ERROR in ARFC_RUN.
    We are using: CRM 3.0 with the following service packs:
    SAP Basis release 610 level 38
    SAP ABA Release 50A level 38
    BBPCRM Release 300 level 17
    Points will be given.
    Thank you.

    Hi Surendra,
    I was expirenced with the error, Basis people had resolved that for me,
    better to post this issue to them,
    this problem for all data sources or any perticulat data source when scheduling infopackage.
    Regards
    Vijay

  • Locking a Table

    I just wanted to know , how the lock works on a table. I am very much confused..
    Let me put down my requirement...
    I am inserting a new record in a Table(Batches) for which one of the columns(no_batch) is an incrementing value. To acheive this, I select the max value of the above column from the same table and add 1 to it.
    (Pl note: I cannot use sequence for this
    nor I cannot have an UNIQUE constraint on this Column... )
    Then I insert this new Record.
    The problem what i faced was...
    When Multiple users accessed to insert the record at the same time,
    Selecting and inserting on the table allowed duplicate values to be inserted on the no_batch column in the batches Table.
    Is there any way out to lock the Table exclusively, when a user is accessing this Table until he/she gives a COMMIT or ROLLBACK operation on the Table.
    so that the next user should wait for the Resources.
    The Time delay is okay for me.
    Here is the skeleton of my insert procedure..
    PROCEDURE insert_record IS
    BEGIN
    <set of statements>
    SELECT max(no_batch) + 1
    into var_no_batch
    from batches
    where <conditions> ;
    insert into batches values
    (val1, val2, val3,var_no_batch,........);
    commit;
    END;
    I have an alternative, but I dont know whether this will work out.
    Can I give an UPDATE statement which will update 0 rows on the same Table, so that it will be locked, and then, I SELECT and INSERT on the same table, which I guess will work, and a COMMIT will release the LOCK on this Table..
    Let me know if this is correct...
    This is very urgent.....
    Any help and suggestions would be greatly appreciated. and Thanks in Advance..
    null

    Thanks for your Help and Suggestions...
    Sorry,I cannot use a select for update Clause, since the select has an aggregate function.
    There are some other procedures which access this Table(only select statements). Will this LOCK stop the other users also who access this Table through the SELECT procedures. Please let me know about that.

  • Lock the table by user with grant only for select

    Hallo.
    It is possible that the user has rights only for SELECT, do not lock the table? Now, where do "SELECT * FROM table FOR UPDATE", does not make the change, but it locks the entire table, and another user to get into it.
    Thanks

    And here is the "evidence" ;)
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL> create user u1 identified by u1 ;
    User created.
    SQL> grant connect to u1 ;
    Grant succeeded.
    SQL> connect hr/hr
    Connected.
    SQL> create or replace view v_t1 as select username, user_id, created from t1 group by username, use
    r_id, created with read only ;
    View created.
    SQL> grant select on v_t1 to u1 ;
    Grant succeeded.
    SQL> connect u1/u1
    Connected.
    SQL> select * from hr.v_t1 where rownum = 1 for update ;
    select * from hr.v_t1 where rownum = 1 for update
    ERROR at line 1:
    ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
    SQL> select * from hr.v_t1 where rownum = 1
      2  ;
    USERNAME                          USER_ID CREATED
    AK                                     36 08-MAY-00

  • Locking a table and then releasing the lock...

    Gurus,
    I ant to lock a table DMS_LO_CD1 and then do certain upodate and then release the lock after that.
    How can I d this ?
    Thanks.
    Regards,
    Rajesh.

    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
    https://forums.sdn.sap.com/click.jspa?searchID=115258&messageID=2656474
    Do the following steps..
    GO TO SE11
    Select the radio button "Lock object"..
    Give the name starts with EZ or EY..
    Example: EYTEST
    Press Create button..
    Give the short description..
    Example: Lock object for table ZTABLE..
    In the tables tab..Give the table name..
    Example: ZTABLE
    Save and generate..
    Your lock object is now created..You can see the LOCK MODULES..
    In the menu ..GOTO -> LOCK MODULES..There you can see the ENQUEUE and DEQUEUE function
    Hope this helps.
    Regards,
    Midhun Abraham

Maybe you are looking for