Verify INSERT logic with SQL Server SELECT command
By: Jeremy Kadlec
Once you have executed the three commands it is time to verify the results. How can we accomplish this? We have to issue SELECT statements to review the data. You did not think you were going to get exposed to another command, did you?
In the code below, we are retrieving all of the columns and all of the rows from the dbo.Customers table.
SELECT CustomerID, FirstName, LastName, PhoneNumber, EmailAddress, Priority, CreateDate FROM dbo.Customer; GO
Here are the results:
As you can see in the first example above, the first row has the following:
- All of the columns have the values from the INSERT command above.
In the second example above, the second row has the following:
- All of the columns have the values from the INSERT command above with the exception of the CreateDate column which was recorded when the record was inserted.
In the third example above, the third row has the following:
- All of the columns have the values from the INSERT command above including NULL for the EmailAddress column.
As you can see from the code and data above, all three rows were properly inserted into the dbo.Customer table. Although they are all correct, I would generally recommend using the syntax from the first example because it is the most complete and there is little guesswork as to the final values.
For more information about the SELECT command, check out the SQL Server SELECT tutorial.
Now that we have covered three basic examples, let's see how else we can use the INSERT command.