
- DBMS Tutorial
- DBMS - Home
- DBMS - Overview
- DBMS - Architecture
- DBMS - Data Models
- DBMS - Data Schemas
- DBMS - Data Independence
- Entity Relationship Model
- DBMS - ER Model Basic Concepts
- DBMS - ER Diagram Representation
- DBMS - Generalization, Aggregation
- Relational Model
- DBMS - Codd's Rules
- DBMS - Relational Data Model
- DBMS - Relational Algebra
- DBMS - ER to Relational Model
- DBMS- SQL Overview
- Relational Database Design
- DBMS - Database Normalization
- DBMS - Database Joins
- Storage and File Structure
- DBMS - Storage System
- DBMS - File Structure
- Indexing and Hashing
- DBMS - Indexing
- DBMS - Hashing
- Transaction And Concurrency
- DBMS - Transaction
- DBMS - Concurrency Control
- DBMS - Deadlock
- Backup and Recovery
- DBMS - Data Backup
- DBMS - Data Recovery
- DBMS Useful Resources
- DBMS - Quick Guide
- DBMS - Useful Resources
- DBMS - Discussion
Explain about insert command in Structured query language in DBMS
Insert command is data manipulation commands, which is used to manipulate data by inserting the information into the tables.
This command is used to add records to a table. While inserting a record using the insert statement, the number of records being entered should match in the columns of the table. In case the number of items being created is less than the number of columns, the field names also need to be specified along with the insert statement.
Insert command
It is used for inserting the records into the table.
The syntax is as follows −
INSERT INTO table-name VALUES(field1, field2,……..)
Example
Given below is an example for the command: INSERT INTO student values(101,’bob’,’CSE’).
create table employee(ename NVARCHAR2(30),department NCHAR2(20)); insert into employee values('pinky’,'CSE'); insert into employee values('priya','ECE'); insert into employee values('hari','EEE'); select * from employee;
Output
You will get the following output −
pinky|CSE priya|ECE hari|EEE
Inserting a record that has some null attributes
It requires identifying the fields that actually get data.
The syntax is as follows −
INSERT INTO table-name(field1,field4) VALUES (value1,value2);
Example
Given below is an example of insert command used for inserting a record that has some null attributes −
create table employee(ename varchar2(30),department char(20), age varchar2(30), marks number(30)); INSERT INTO employee(ename,marks) VALUES ('lucky',450); INSERT INTO employee(ename,marks) VALUES ('bob',300); select * from employee;
Output
You will get the following output −
lucky|||450 bob|||300
Inserting records from another table
Insert command is used to insert the values which are present in another table.
The syntax is as follows −
INSERT INTO table-name1 SELECT * FROM table-name2;
Example
Given below is an example of insert command for inserting records from another table −
create table employee(ename varchar(30),department varchar(20)); insert into employee values('pinky','CSE'); insert into employee values('priya','ECE'); insert into employee values('hari','EEE'); select * from employee; create table department(name varchar(30),dname varchar(30)); insert into department select * from employee; select * from department;
Output
You will get the following output −
pinky|CSE priya|ECE hari|EEE pinky|CSE priya|ECE hari|EEE
- Related Articles
- Explain about Create, Insert, Select command in structure query language (DBMS)?
- Structured Query Language (SQL)
- Explain Select command in DBMS
- What is a query language in DBMS?
- Explain about nested queries in DBMS
- Explain about concurrent transactions in DBMS
- Explain about conflict serializability in DBMS
- Explain the use of delete command in DBMS
- Difference between SQL(Structured Query Language) and T-SQL(Transact-SQL).
- Explain about 2NF with an example in DBMS
- Explain about triggers and active databases in DBMS
- Explain about the Time stamp ordering protocol in DBMS
- Print structured MySQL SELECT at command prompt
- Explain about link and definition section in C language
- Explain about two phase locking (2PL) protocol(DBMS)
