开发者

Database creation with data insertion using mysql

Cannot insert the value NULL into column 'Quantity', table 'UOKA0209.dbo.SalesOrderLine'; column does not allow nulls. INSERT fails.

Here is the error message I am getting, can you suggest any fixes? I am new to this and don't have much experience working in with this language.

INSERT INTO [SalesOrderLine] ([SOLID],[Quantity],[SQLStatus])
VALUES
  (1896,default,default),
  (1789,default,default),
  (3789,开发者_Go百科default,default),
  (4789,default,default),
  (5789,default,default);
  

This is what I have tried.


You cannot use default if there is no default set in the database for null values. So instead you can change it to be nothing --> '' which is NOT NULL even though it's "empty" -- Or set a default for your NOT NULL field (Quantity) using ALTER

INSERT INTO UOKA0209.dbo.SalesOrderLine (`SOLID`, `Quantity`, `SQLStatus`) 
VALUES 
(1896,'',default),
(1789,'',default),
(3789,'',default),
(4789,'',default),
(5789,'',default);

Or alter your table:

 ALTER TABLE UOKA0209.dbo.SalesOrderLine 
     MODIFY Quantity INT NOT NULL DEFAULT 0;

And just an assumption -- You'll probably have the same problem with SQLStatus -- So change your query to: (4789,'',''), OR alter that column using the same alter command above, setting it to 0 by default .. MODIFY SQLStatus INT NOT NULL DEFAULT 0;

CONVERSELY -- If you did alter your table, and set the defaults for those two columns to 0 .. That makes your query much simpler:

INSERT INTO UOKA0209.dbo.SalesOrderLine (`SOLID`) 
VALUES 
(1896),
(1789),
(3789),
(4789),
(5789);

As Quantity and SQLStatus will now default to 0 without needing input from you to do so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜