SQL Foundations  «Prev 

SQL Statement that will not work

Here is an example of a statement that will not work:

values ("Thomas", "Hauck")

The engine will tell you that you cannot insert the information because it doesn't match the format of the table.
Here's an example of the error message you will receive from SQL Server:
Msg 213, Level 16, State 4
Insert error: column name or number of supplied
values does not match table definition.

You have three columns in the table, but only two data elements were provided. Either you need to tell the engine where the information needs to be placed by indicating the column names, or you need to provide the same number and order of data elements so that they match your database table.

SQL Queries
INSERT INTO myLibrary VALUES (‘SQL Bible by Alex Kriegel Boris M. Trukhnov
Paperback: 888 pages Publisher: Wiley; 2 edition (April 7,2008)
Language:English ISBN-13: 978-0470229064’);

keywords INSERT

The keywords INSERT, INTO, and VALUES are the elements of the SQL language and together instruct the RDBMS to place the character data (in the parentheses, surrounded by single quotation marks) into the database table. Note that we did not indicate the column name; first because we have but a single column in which to insert, and second because RDBMS is smart enough to figure out what data goes where by matching a list of values to the implied list of columns. Both parentheses and quotation marks are absolutely necessary: the former signifies a list of data to be inserted, and the latter tells the RDBMS that it is dealing with text (character data type).
In database parlance, we have created a record in the table. There are many more books on thevshelf, so how do we enter them? One way would be to add all of them on the same line, creating avhuge single record. Although that is possible, within limits, it would be impractical, creating a pilevof data not unlike the refrigerator model we discussed earlier: easy to add and difficult to find. Do I hear "multiple records"?
Answer: Yes
The previous statement could be repeated multiple times with different data until all books are entered into the table; creating a new record every time. Instead of a refrigerator model with all data all in one place, we moved onto “chest drawer model” with every book having a record of its own.