msg213 error when trying to insert data

Hello!

I am trying to learn more about xml and sql-server. I have a copy of the book Sql server 2005 express edition for dummies from which I try to follow the exact instructions. I have not found any information on the books website that anything is wrong so assume I  missunderstand some detail.

The problem (Msg 213, Level 16, State 1, Line 1
Column name or number of supplied values does not match table definition.
)
 arise when I try to execute the following command in MS sql server management studio:

INSERT INTO Shipments VALUES(1,'<Root>
<Parts OrderID="1" PurchaseOrderNumber="NSSDJS#1">
<DeliveryDate>2006-12-30</DeliveryDate>
<Items>
   <ShipmentWeight>2.44</ShipmentWeight>
     <LineItem>
	        <Name>DentaKit for Adults</Name>
	        <Code>DK-R001</Code>
	        <Price>29.95</Price>
     </LineItem>
     <LineItem>
	        <Name>Retainer Brite 1 Year</Name>
	        <Code>DK-RB1Y</Code>
	        <Price>35.00</Price>
     </LineItem>
</Items>
</Parts>
</Root>')
GO

Open in new window


Before, I have used these statements to create xm-schema and a table.

CREATE XML SCHEMA COLLECTION Parts AS
N'<?xml version="1.0" encoding="UTF-16"?>
<xsd:schema
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <xsd:element name="parts">
  <xsd:complexType>
   <xsd:choice  minOccurs="0" maxOccurs="unbounded" > 
    <xsd:sequence>
     <xsd:element name="code" type="xsd:string"/>
     <xsd:element name="name" type="xsd:string"/>
     <xsd:element name="price" type="xsd:decimal"/>
    </xsd:sequence>
   </xsd:choice>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>
'
CREATE TABLE Shipments
(
   ShipmentID INTEGER PRIMARY KEY NOT NULL,
   ShipmentDate DATETIME NOT NULL,
   ShippedParts XML (Parts)
)
GO

Open in new window


Please, give me a hint on what to change to make it work. More info can be found in attached file

Best regards
Marcus Steen
msg213.pdf
marcguAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brendt HessSenior DBACommented:
You are missing the date field.  With your table having a shipping id, a shipment date, and the  shippedParts XML field, you need to include all three in your VALUES statement.  Try this:

INSERT INTO Shipments VALUES(1, CURRENT_TIMESTAMP, 
'<Root>
<Parts OrderID="1" PurchaseOrderNumber="NSSDJS#1">
<DeliveryDate>2006-12-30</DeliveryDate>
<Items>
   <ShipmentWeight>2.44</ShipmentWeight>
     <LineItem>
	        <Name>DentaKit for Adults</Name>
	        <Code>DK-R001</Code>
	        <Price>29.95</Price>
     </LineItem>
     <LineItem>
	        <Name>Retainer Brite 1 Year</Name>
	        <Code>DK-RB1Y</Code>
	        <Price>35.00</Price>
     </LineItem>
</Items>
</Parts>
</Root>')
GO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marcguAuthor Commented:
Hi!

Thanks for your comment, It's leading me  closer to the solution, but still something is wrong because I now get the following error-message:

Msg 6913, Level 16, State 1, Line 1
XML Validation: Declaration not found for element 'Root'. Location: /*:Root[1]



I don't understand what I have to to do.
0
Brendt HessSenior DBACommented:
Your Schema doesn't have the <Root> element defined in it.  In a CREATE XML SCHEMA COLLECTION declaration, the first element defined becomes the root element of the document.  So, in your case, the root element is <Parts>.

There is a much more detailed explanation in this article at Beyond Relational, coder's website that I really like.
0
marcguAuthor Commented:
Hi!

Thanks for the link.

 All of the examples in the article as well as this works now:

DECLARE @cust AS XML(Parts)
SET @cust = '<parts></parts>'

Open in new window


But, no matter how I try to change the code and remove <root></root> I, will still get msg6913 error message.

Msg 6913, Level 16, State 1, Line 1
XML Validation: Declaration not found for element 'Parts'. Location: /*:Parts[1]


For instance, I tried like this (and several other options)

INSERT INTO Shipments VALUES(1, CURRENT_TIMESTAMP, 
'<Parts OrderID="1" PurchaseOrderNumber="NSSDJS#1">
<DeliveryDate>2006-12-30</DeliveryDate>
<Items>
   <ShipmentWeight>2.44</ShipmentWeight>
     <LineItem>
	        <Name>DentaKit for Adults</Name>
	        <Code>DK-R001</Code>
	        <Price>29.95</Price>
     </LineItem>
     <LineItem>
	        <Name>Retainer Brite 1 Year</Name>
	        <Code>DK-RB1Y</Code>
	        <Price>35.00</Price>
     </LineItem>
</Items>
</Parts>')
GO

Open in new window




In case you or any one else has a final clue what´s going wrong for me, I will award you the points. You have actually answerd my original question. For me, it´s just annoying when I do not understand why I fail to follow the example.

/Marcus
0
marcguAuthor Commented:
This solved my initial question perfectly.

However, the solution showed that I had more problems which I probably have to adress in a new question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.