SQL: insert records is not in order
I am having a problem while a record is inserted into a table.
each parking_cost is inserted after its related record. It should be with its record. why is this happening?
Any ideas ?
Regards. 开发者_如何学C
If you are doing two separate queries to populate the row in the table, the first query needs to be an INSERT, the second query needs to be an UPDATE, eg:
INSERT INTO Customers (Pre_Payed_Card, Parking_ID) VALUES ('1234', 1)
Then
UPDATE Customers SET Parking_Cost = <cost> WHERE Parking_ID = 1
An INSERT will always create a new row; two INSERT queries for the same logical entity will result in two separate rows like you have in the screenshot.
Update: re-reading that query, you're probably after something like
UPDATE Customers SET Parking_Cost = p.Parking_Cost
FROM Customers c INNER JOIN Parking p ON c.Parking_ID = p.Parking_ID
WHERE c.Parking_ID = 1
精彩评论