Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL Server - Get Started
  • Install SQL Server
  • SQL Server Management Studio
  • SQL Server - Windows Authentication
  • SQL Server - Authentication
  • SQL Server - Create New User
  • SQL Server - GRANT/REVOKE Permissions to User
  • SQL Server - Data Types
  • SQL Server - Naming Conventions
  • SQL Server - CREATE Database
  • SQL Server - CREATE Table
  • Add Columns
  • Identity Column
  • Rename Column, Table
  • Drop Columns
  • SQL Server - Schema
  • SQL Server - Tables Relations
  • SQL Server - Primary Keys
  • Modify/Delete Primary Keys
  • SQL Server - Foreign Keys
  • Modify/Delete Foreign Keys
  • SQL Server - Check Constraints
  • SQL Server - Unique Constraints
  • SQL Server - Views
  • Modify/Delete Views
  • SQL Server - Functions
  • SQL Server - Stored Procedures
  • Stored Procedure Parameters
  • SQL Server - Indexes
  • Non-clustered Indexes
  • Modify/Delete Indexes
  • SQL Server - Triggers
  • DDL Triggers
  • LOGON Triggers
  • Enable/Disable Triggers
  • Modify/Delete Triggers
  • SQL Server - Sequence
  • SQL Server - Synonyms
  • SQL Server - IF ELSE Statement
  • SQL Server - Loops
  • SQL Server - Insert Data
  • SQL Server - Update Data
  • SQL Server - Delete Data
  • SQL Server - Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL Server - Inner Join
  • Left Join
  • Right Join
  • Full Join
  • Self Join
  • Dynamic SQL
  • Built-in Functions
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

Insert Data into Tables in SQL Server using INSERT Statement

The INSERT INTO statement is used to insert single or multiple records into a table in the SQL Server database.

Syntax:

INSERT INTO table_name(column_name1, column_name2...) VALUES(column1_value, column2_value...);

Here, we will insert data into the following Employee table which we created in the Create Table chapter.

The following INSERT INTO statement will insert a single row in all columns of the above Employee table in the SQL Server database.

T-SQL: Insert Data
INSERT INTO Employee(FirstName, LastName, EMail, Phone, HireDate, Salary)
VALUES('John','King','[email protected]','123.123.0000','01-01-2015', 33000);

Note that EmployeeId column is an identity column, so the values will be auto-generated on each insert statement. So, EmployeeId column is not included in the above insert statement.

To see the inserted data, execute the Select * from Employee; query in the query editor, as shown below.

Insert Values to All Columns

To insert values to all columns of a table, you don't need to specify column names with the table name. Specify the values for each column in a sequence as they appear in the table, as shown below.

T-SQL: Insert Data
INSERT INTO Employee
VALUES('Neena','Kochhar','[email protected]','123.000.000','05-12-2018',17000);

Any change in the sequence, the number of values, or its data type may result in an error or incorrect data.

Insert Values to Specific Columns

To insert data into specific columns, specify the column names in the parenthesis. Make sure other columns allow null values; otherwise, an error will be raise.

The following will insert data in FirstName, and LastName columns only.

SQL Script: Insert Data to Specific Columns
INSERT INTO Employee 
VALUES 
('Kevin','Weiss','[email protected]','123.123.12','08-10-2019',17000),
('Lex','De Haan','[email protected]','123.123.13','05-05-2019',15000),
('Laura','Bissot','[email protected]','123.123.15','02-08-2019',40000);

To insert multiple records into specific columns, specify the column names in the parenthesis, as shown below.

T-SQL: Insert Multiple Records in Specific Columns
INSERT INTO Employee(FirstName, LastName) 
VALUES 
('Kevin','Weiss'),
('Lex','De Haan'),
('Laura','Bissot');

Now, execute the Select * from Employee query will display the following result.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.