SQL INSERT

Write SQL INSERT queries.

Create Table script


create table Customer (
    ID number constraint customer_pk primary key,
    Name varchar2(20)
);
/

Query: Insert query with Primary key fields


insert into Customer (ID,Namevalues(1,'Ram');
insert into Customer (ID,Namevalues(2,'Henry');
insert into Customer (ID,Namevalues(3,'Sam');
insert into Customer (ID,Namevalues(4,'Shyam')

Result: 

Table: Customer
+----+-------+
| Id | Name  |    
+----+-------+
1  | Ram   |
2  | Henry |
3  | Sam   |
4  | Shyam |
+----+-------+

Query Insert query if a primary key is autogenerated

insert into Customer (Namevalues('Ram');
insert into Customer (Namevalues('Henry');
insert into Customer (Namevalues('Sam');
insert into Customer (Namevalues('Shyam');

Result: 

Table: Customer
+----+-------+
| Id | Name  |    
+----+-------+
1  | Ram   |
2  | Henry |
3  | Sam   |
4  | Shyam |
+----+-------+

Query Insert query without defining the column name

insert into Customer values(1,'Ram');
insert into Customer values(2,'Henry');
insert into Customer values(3,'Sam');
insert into Customer values(4,'Shyam')

Result: 

Table: Customer
+----+-------+
| Id | Name  |    
+----+-------+
1  | Ram   |
2  | Henry |
3  | Sam   |
4  | Shyam |
+----+-------+


Related post

  1. Write SQL statement to create a table
  2. Create a table from another table with data, without data, filtered data, and specific columns


No comments:

Post a Comment