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
Newsletter
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

  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Android Application Security: Android Application Architecture
  • Building a Software Factory With AI Agents and Workflows
  • Grounding AI Agents in Governed Data

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Nov. 01, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
22.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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