In the INSERT statement that follows, assume that all of the table and column names are spelled correctly, that none of the columns are identity columns, and that none of them have default values or accept null values. What’s wrong with the statement? INSERT INTO InvoiceCopy (VendorID, InvoiceNumber, InvoiceTotal, PaymentTotal, CreditTotal, TermsID, InvoiceDate, InvoiceDueDate) VALUES (97, '456789', 8344.50, 0, 0, 1, '2016-08-01');A) The column names in the column list are in the wrong sequence.B) The values are in the wrong sequence.C) There are zeroes in the VALUES list.D) The number of items in the column list doesn't match the number in the VALUES list.

Answer :

segdavids

Answer:

The correct answer is

D. The number of items in the column list doesn't match the number in the VALUES list.

Explanation:

When performing an insert action, the number of values to be inserted into each columns Must match the number of the columns that have been mentioned.

Now let us look at the question as given:

INSERT INTO InvoiceCopy (VendorID, InvoiceNumber, InvoiceTotal, PaymentTotal, CreditTotal, TermsID, InvoiceDate, InvoiceDueDate) VALUES (97, '456789', 8344.50, 0, 0, 1, '2016-08-01')

From the insert statement above, we have declared the system to insert into 8 columns( VendorID, InvoiceNumber, InvoiceTotal, PaymentTotal, CreditTotal, TermsID, InvoiceDate, InvoiceDueDate) of the table InvoiceCopy, but the number of values to be inserted into each column respectiveley is 7.  So the statement will try to insert value 97 into column VendorID, Value 456789 into column InvoiceNumber, Value 8344.50 into InvoiceTotal, Value 0 into column PaymentTotal, Value 0, into Column CreditTotal, Value 1, into Column  TermsID, Value '2016-08-01' into Column   InvoiceDate, But null will be inserted into Column InvoiceDueDate, However, the Question states that None of these columns Accept Null Values. This means that we have to specify values for EVERY column we want to insert into. Because of this number mismatch, the computer will throw an error. This is what is Wrong with the statement.

An insert statement is used to add new values to a database. When performing an insert statement, there are 3 main information that needs to be defined:

  1. The name of the table that the new data is being inserted into
  2. The name of the columns that you want to insert the values into
  3. The actual values that you want to add to the columns mentioned in (2) above.

The basic syntax of an insert statement is as follows:

INSERT INTO table_name (column1_name, column2_name, ...)

 VALUES (data_for_column1, data_for_column2, ...);

Other Questions