java2db

Insert record in table using sql



Possibly two ways to insert record in table using sql ‘INSERT INTO‘ statement.Pass the suitable values to the table columns based on it’s type and size using sql statement .

 

Insert record in table using sqlInsert  record  without specifying the column names :

Syntax:

INSERT INTO table_name VALUES(val1 , val2 , val3, …..);

Example sql statement :

Result :

E_NO
E_NAME
E_GENDER
E_SALARY
E_ADDRESS
E_JOIN_DATE
E_IN_TIME
1 Rose F 10000 street10,xxx,UK 03-MAR-13 10-MAR-13 12.10.10.0

Insert record in table using sql  The above sql statement added one record to the table with E_NO=1.

Insert record in table using sql  It require to pass all the column values based on it’s  type and size, otherwise it gives error.

 

 

Insert record in table using sqlInsert record with specific column values :

Syntax:

INSERT INTO(column1,column2,column3,…) table_name VALUES(val1,val2,val3,…..);

Example sql statement :

Result :

E_NO
E_NAME
E_GENDER
E_SALARY
E_ADDRESS
E_JOIN_DATE
E_IN_TIME
1 Rose F 10000 street10,xxx,UK 03-MAR-13 10-MAR-13 12.10.10.0
2 Tom null 10000  null 05-MAR-13 10-MAR-13 12.10.10.0

Insert record in table using sql  The unspecified columns inserted with null.

Insert record in table using sql  If any column having key constrain (Ex:primary key) , in that case, it is mandatory to pass a

…….suitable value for it.

 

Note : We can insert data to a table  ,by selecting  values from another table .

The above statement will insert the records from BIODATA table to EMP_DETAILS table . If you want to insert a specific record , use the WHERE clause .




Related Posts :
Sql FOREIGN KEY constraint on table column
Sql CHECK constraint on table column
Sql NOT NULL constraint on table column
Sql UNIQUE constraint on table column
Sql PRIMARY KEY constraint on table column
Sql full outer join on tables with an example
Sql right outer join on tables with an example
Sql left outer join on tables with an example
   [will not be published]



^ <