Insert Clause


What is the query?

The query is a statement written to perform some operation on selected data from a SQL table or an HQL object. You can perform various operations by writing queries, like CRUD operations (create, read, update, delete) and many more. Using queries, we can do multiple operations, not only these basic operations, and make the database much more powerful and flexible.

Insert Clause

As its name suggests, an insert clause is used to insert records in the database. You can insert data anywhere in the database using the insert clause. By putting some conditions in the insert query, you can add the records anywhere in the database.

Syntax :

Insert into table_name (column_name) select object.column from table_name object_name

How to write Insert Query in HQL

Query query = session.createQuery (“insert into EMP(emp_id, emp_name)” + “select emp_no, emp_nm from backup_emp” );

Int result = query.executeUpdate();

Advantages of HQL 

  1. ORM: HQL ORM easily solves the problem of mismatched data found in object-oriented and relational databases.
  2. Independent database: HQL is database-independent. It can connect any database like oracle, Mysql, etc.
  3. Open Source: HQL supports open-source language features. Anyone can make their community and use it.