BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

DBMS SQL Insert Statement

By Chaitanya Singh | Filed Under: DBMS

INSERT statement is used to insert the data into the table in database. You can insert values of specified columns or an entire record containing the values for all the columns of the table. In this guide, you will learn how to use SQL Insert statement with examples.

Syntax: For inserting an entire row with all the column values:

INSERT INTO TABLE_NAME    
VALUES (value1, value2, value 3, .... Value N);

Syntax: For inserting a record with only certain column values:

INSERT INTO TABLE_NAME    
(col1, col2, col3,.... col N)   
VALUES (value1, value2, value 3, .... Value N);    

The above syntax can also be used for inserting a complete record with all values, however mentioning column names in that case would be unnecessary.

INSERT Statement Example

Let’s take a look at the table STUDENT in database:

STU_IDSTU_NAMEAGEADDRESS
1001Oliver22Las Vegas
1002Ajeet18San Diego
1003Jadie19Nashville
1004Lucy20Chicago
1005Tina22New York

Inserting an entire row into the table

INSERT INTO STUDENT VALUES (1006, 'Jane', 21, 'Boston');  

Result: The table would look like this after inserting the row using INSERT statement:

STU_IDSTU_NAMEAGEADDRESS
1001Oliver22Las Vegas
1002Ajeet18San Diego
1003Jadie19Nashville
1004Lucy20Chicago
1005Tina22New York
1006Jane21Boston

Inserting a row with only selected column values

Let’s insert another row into the STUDENT table. This time, we will enter a record with only STU_ID, STU_NAME and AGE field. Here we are only inserting three values into the table, however the record in this table has four attributes, in this case we need to specify the column names for which we are inserting the values.

INSERT INTO STUDENT (STU_ID, STU_NAME, AGE)
 VALUES (1007, 'Dwayne', 20); 

Result: Since we didn’t specify the value for ADDRESS field for the newly inserted record, it shows address field as null for that record.

STU_IDSTU_NAMEAGEADDRESS
1001Oliver22Las Vegas
1002Ajeet18San Diego
1003Jadie19Nashville
1004Lucy20Chicago
1005Tina22New York
1006Jane21Boston
1007Dwayne20null
❮ SQL SELECT

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

DBMS Tutorial

Basics

  • DBMS Tutorial
  • DBMS Introduction
  • Database Applications
  • DBMS vs File System
  • DBMS vs RDBMS
  • DBMS Architecture
  • Three-level DBMS architecture
  • View in DBMS
  • Abstraction
  • Instance & Schema
  • DBMS languages

Data Models

  • Data Models
  • ER Diagram
  • ER Design issues
  • Convert ER to table
  • DBMS Generalization
  • DBMS Specialization
  • DBMS Aggregration
  • Relational Model
  • Hierarchical Model
  • Constraints
  • Cardinality

Relational Database

  • RDBMS concepts
  • Relational Algebra
  • Relational Calculus
  • Keys Index
  • Primary Key
  • Super Key
  • Candidate Key
  • Foreign Key
  • Composite Key
  • Alternate Key

Normalization

  • Normalization
  • Functional dependency

Transaction Management

  • Transaction Management
  • ACID properties
  • Transaction States
  • DBMS Schedules
  • Serializability
  • Conflict Serializability
  • View Serializability
  • Recoverability Of Schedule
  • Failure Classification
  • Log based Recovery
  • DBMS Checkpoint
  • Deadlock

Concurrency Control

  • Concurrency Control
  • Lock based protocol
  • Timestamp based protocol
  • Validation based protocol

File Organization

  • File Organization
  • Sequential File Organization
  • Heap File Organization
  • Hash File Organization
  • DBMS ISAM
  • B+ File Organization
  • Cluster File Organization

SQL Introduction

  • SQL Introduction
  • SQL Characteristics
  • Advantages of SQL
  • SQL Commands
  • SQL Operators
  • SQL CREATE
  • SQL DROP
  • SQL SELECT
  • SQL INSERT

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap