SQL Server INSERT INTO Table VALUES: Step-by-Step
In this article
To add a row to a SQL Server table with literal values, use the syntax INSERT INTO dbo.TableName (Column1, Column2) VALUES ('Value1', 'Value2');. List the columns you are filling, then supply one value per column in the same order, with text in single quotes and numbers unquoted. That single statement is the whole answer; the rest of this guide covers doing it safely, the errors you will hit, and the variations worth knowing.
What You'll Need
- A SQL Server instance you can connect to, and permission to insert into the target table (typically
INSERTrights on that table or its schema). - A client tool such as SQL Server Management Studio (SSMS), Azure Data Studio, or
sqlcmd. - The table must already exist.
INSERTadds rows; it does not create the table. - Knowledge of the column names, their data types, and which columns are nullable or have defaults.
Step-by-Step
- Connect to the right database. In SSMS or Azure Data Studio, open a new query window against the database that contains your table. If you are unsure which database is active, run
SELECT DB_NAME();. To switch explicitly, runUSE YourDatabaseName;followed byGOon its own line. Menu labels differ slightly between versions and tools, but the query approach works everywhere. - Inspect the table first. Run
EXEC sp_help 'dbo.YourTable';or expand the table in Object Explorer and look at its Columns. Note which columns areNOT NULLwithout a default, which are identity columns, and which have defaults. This prevents most insert errors before they happen. - Write the INSERT statement with an explicit column list. For example:
INSERT INTO dbo.Customers (FirstName, LastName, Email) VALUES ('Ana', 'Lopez', 'ana@example.com');. Always name the columns. Without a column list, SQL Server expects a value for every column in table order, including identity columns, and the statement breaks the moment the schema changes. - Match values to data types. Put strings and dates in single quotes (
'2024-05-01'), leave numbers and bit values unquoted (42,1), and useNULL(no quotes) for a missing value in a nullable column. Escape an apostrophe inside a string by doubling it:'O''Brien'. - Execute the statement. Press F5 in SSMS or click Run. The Messages tab should report something like (1 row affected). If you see an error instead, jump to Troubleshooting below.
- Verify the row. Run
SELECT TOP (5) * FROM dbo.Customers ORDER BY CustomerID DESC;(adjust the key column). Confirm the values landed as intended and that defaults or identity values were generated correctly. - Insert multiple rows in one statement when appropriate. SQL Server accepts a comma-separated list of value tuples:
INSERT INTO dbo.Customers (FirstName, LastName) VALUES ('Ana','Lopez'), ('Ben','Ng'), ('Cara','Diaz');. This is one statement and one transaction, which is faster and easier to roll back than three separate inserts. - Wrap risky batches in a transaction. For anything beyond a quick test, use
BEGIN TRANSACTION;, run your inserts, check the row counts, thenCOMMIT;orROLLBACK;. This lets you undo a mistake without restoring a backup.
Common Mistakes
- Omitting the column list. The most common cause of "Column name or number of supplied values does not match table definition." It also silently breaks when columns are added or reordered.
- Supplying a value for an identity column. Unless you have explicitly enabled
SET IDENTITY_INSERT dbo.Table ON;(and turned it off afterwards), SQL Server generates that value itself and rejects your input. - Quoting numbers.
'42'may convert implicitly, but relying on implicit conversion hides bugs and can fail under strict settings. Quote only text and dates. - Forgetting required columns. A
NOT NULLcolumn with no default must appear in your column list with a value, or the insert fails. - Date format ambiguity. Use unambiguous formats such as
'YYYYMMDD'or ISO 8601 ('2024-05-01T00:00:00') rather than locale-dependent forms like'05/01/2024'. - Running against the wrong database. The table may exist in more than one database; check
DB_NAME()before executing.
Tips
- Schema-qualify table names (
dbo.Customers) so the statement does not depend on the user's default schema. - Use
OUTPUT INSERTED.*on the INSERT to see exactly what was written, including generated identity values, in one round trip. - For bulk loads of hundreds or thousands of rows, prefer
BULK INSERTor SQL Server Integration Services over longVALUESlists; very long lists hit statement size and parser limits. - Keep a scratch copy of the statement with placeholder values so you can rerun it during testing without retyping.
- If the table has triggers, remember they fire per statement, which can affect performance and side effects on multi-row inserts.
Troubleshooting
Work through these in order; the first two resolve most failures.
- Read the error message literally. "Invalid object name" means the table is not in the current database or schema, or you lack permission. "Cannot insert the value NULL into column" names the exact column you missed. "String or binary data would be truncated" means a value is longer than the column allows.
- Check the column count and order. Compare your column list against the value list one by one. A mismatch of one is easy to miss in a long statement.
- Check permissions. If you get a permission error, ask the database administrator to grant
INSERTon the table. Do not attempt to work around permissions. - Check constraints. Foreign key, check, and unique constraints can reject otherwise valid-looking rows. Query the table's constraints in Object Explorer to see what is enforced.
- Test with a single row first. If a multi-row insert fails, reduce it to one tuple to isolate the offending values, then add rows back.
- Roll back if needed. If you are inside an open transaction, run
ROLLBACK;before retrying so a partial change does not linger.
Frequently Asked Questions
Do I have to list every column in the INSERT statement?
No. You only need to list the columns you are supplying values for, provided every other column is nullable, has a default, or is an identity column. Columns you omit receive their default or NULL.
How do I insert the current date and time?
Use the built-in function directly in the VALUES list, for example VALUES (GETDATE()), rather than typing a literal timestamp.
Can I insert into a table without a column list?
Yes, but only if you supply a value for every column in the table's defined order, including identity columns (which then require SET IDENTITY_INSERT). Naming columns is safer and strongly recommended.
How many rows can one INSERT statement add?
The practical limit is the 1,000-row cap on a single VALUES clause. For larger loads, split into batches or use BULK INSERT.
Why did my insert succeed but the row is not there?
You are most likely inside an uncommitted transaction in the same session, or you queried a different database or schema. Run SELECT @@TRANCOUNT; and confirm the database with DB_NAME().
Does INSERT INTO ... VALUES work the same in Azure SQL Database?
Yes, the syntax is the same. The differences are in permissions and connection setup, not in the INSERT statement itself.