Free Web Development Online Tutorials, Learn to Code
Learn SQL Database Development, MS SQL Tutorial Online

Insert Query in SQL Server Database

Inserting new record to a database table

Here is the insert query in SQL table

    INSERT INTO TableName
           (field1,field2, field3, field4 )
           (value1, value2, value3,	value4)

While specifying values in insert query, if the value type is string, then you need to pass the value within single quote

Here is an practical example how your SQL query will look like

INSERT INTO [tbContactList]
(   [fullName]
(  'Mr Alexa'
    ,'Google INC'

Now if you notice in above query, for all value types we have used single quote, except date type

Insert Query Failing Reason

Sometimes you may experience that insert query failing, Here are some of the reason to look at to find the root cause

  • If column data type and value data type is not same
  • If the value data length is more than specified in column

If you are inserting more than one table you may need to use Transaction

You should also read Primary Key and Foreign Key

Insert Query in SQL Server Database