DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Recover a Deleted Table in a SQL Server Database
  • Recovering an MS SQL Database From Suspect Mode: Step-By-Step Guide
  • Restoring the MS SQL Server Database in Easy Steps
  • How To Convert MySQL Database to SQL Server

Trending

  • Improving DAG Failure Detection in Airflow Using AI Techniques
  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • From Data Movement to Local Intelligence: The Shift from Centralized to Federated AI
  • Throughput vs Goodput: The Performance Metric You Are Probably Ignoring in LLM Testing
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Use the INSERT Command in SQL Server 2017

How to Use the INSERT Command in SQL Server 2017

The INSERT INTO statement is used to insert new records in a table. Read on to learn three techniques for using this command!

By 
Valiveti Sekhar user avatar
Valiveti Sekhar
·
Nov. 01, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
22.4K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, you will learn how to insert data into a table in SQL Server. The INSERT INTO statement is used to insert new records in a table.

Specifying Column Names and Values to Be Inserted

 Syntax:

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1,value2, value3,...valueN);

Example:

INSERT INTO Customers(CustomerName,Country,City,Age)
VALUES('Valiveti Sekhar','India','Bangalore',35);

Note: SQL requires single quotes around text values. However, numeric fields should not be enclosed in quotes.

Specifying Only the Values to Be Inserted

If you are adding values for all the columns of a table, you do not need to specify the column names in the SQL query. However, make sure that the order of the values is in the same order as the columns in the table.

Syntax:

INSERT INTO TABLE_NAME VALUES (value1, value2, value3,...valueN);

Example:

INSERT INTO Customers VALUES('Valiveti Sekhar','India','Bangalore',35);

Using Another Table

You can insert data into a table through the SELECT statement over another table, provided the other table has a set of fields.

Syntax:

INSERT INTO FIRST_TABLE_NAME (column1, column2, column3,...columnN)
SELECT column1, column2, ...columnN FROM SECOND_TABLE_NAME; 

Example:

INSERT INTO Customers_New(CustomerName,Country,City,Age)
SELECT CustomerName,Country,City,Age FROM Customers; 

Here's a video to clarify you anything you may be confused about:

And here are some additional resources:

  • Microsoft SQL Server 2017 Installation

  • Microsoft SQL Server Online Training

sql Database Microsoft SQL Server Command (computing)

Opinions expressed by DZone contributors are their own.

Related

  • How to Recover a Deleted Table in a SQL Server Database
  • Recovering an MS SQL Database From Suspect Mode: Step-By-Step Guide
  • Restoring the MS SQL Server Database in Easy Steps
  • How To Convert MySQL Database to SQL Server

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook