Tary
Tary

Reputation: 103

Cannot INSERT the following data into MSSQL

im trying to insert the following data into the Table in MSSQL.

(1, 'Tony', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
(2, 'Mark', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
(3, 'Tanya', 5 ,1.81, 65.43, 1, '1957-05-10', NULL),
(4, 'Марк', NULL ,1.81, 65.43, 0, '1957-05-10','Dura bura'),
(5, 'Toncho', 2 ,1.81, 65.43, 0, '1957-05-10','Сто чадъра')

Unfortunately I get 'Arithmetic overflow error converting numeric to data type numeric' and I have no idea why. Here is the code and I just cannot understand why it doesn't work. I tried reading other posts, but I am just starting and I cannot understand most of what is written in the other problem/suggestions :(

   CREATE DATABASE Human
USE Human
CREATE TABLE People
(
    Id INT PRIMARY KEY,
    [Name] NVARCHAR(200) NOT NULL,
    Picture VARBINARY(MAX),
    Height DECIMAL(5,2),
    [Weight] DECIMAL(5,2),
    Gender BIT NOT NULL,
    Birthdate DATETIME NOT NULL,
    Biography NVARCHAR(MAX)
)
INSERT INTO People(Id, [Name], Picture, Height, [Weight], Gender, Birthdate, Biography) VALUES
    (1, 'Tony', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
    (2, 'Mark', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
    (3, 'Tanya', 5 ,1.81, 65.43, 1, '1957-05-10', NULL),
    (4, 'Марк', NULL ,1.81, 65.43, 0, '1957-05-10','Dura bura'),
    (5, 'Toncho', 2 ,1.81, 65.43, 0, '1957-05-10','Сто чадъра')

Upvotes: 0

Views: 163

Answers (2)

Tary
Tary

Reputation: 103

Thank you all. I believe I had some leftovers in the DB or somewhere else that I had not cleared and it was interfering with the code. Restarting the program, deleting everything(i had to delete the DB too or it just happened to work when I did), reconnecting and writing it from scratch solved this issue. Exact code as per request. I was running only the INSERT part when I received the issue. I cannot seem to run the whole code in one go, I must execute it line by line even if no such DB exists.

CREATE DATABASE Human
USE Human
CREATE TABLE People
(
    Id INT PRIMARY KEY,
    [Name] NVARCHAR(200) NOT NULL,
    Picture VARBINARY(MAX),
    Height DECIMAL(5,2),
    [Weight] DECIMAL(5,2),
    Gender BIT NOT NULL,
    Birthdate DATETIME NOT NULL,
    Biography NVARCHAR(MAX)
)
INSERT INTO People(Id, [Name], Picture, Height, [Weight], Gender, Birthdate, Biography) VALUES
    (1, 'Tony', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
    (2, 'Mark', NULL ,1.81, 65.43, 0, '1957-05-10', NULL),
    (3, 'Tanya', 5 ,1.81, 65.43, 1, '1957-05-10', NULL),
    (4, 'Марк', NULL ,1.81, 65.43, 0, '1957-05-10','Dura bura'),
    (5, 'Toncho', 2 ,1.81, 65.43, 0, '1957-05-10','Сто чадъра')

Upvotes: 0

Vladislav Zalesak
Vladislav Zalesak

Reputation: 713

Are you experiencing this problem with provided statement/data or is the statment/data an example and not 1:1?

Works for me. Example

Som maybe some DB/sErver setting that i cant think of of my head.

  1. try to identify row, do a row by row insert, try only 1, only 2 ... only 5, to identify which row(s)
  2. remove columns to check which one it is

is this the exact data you get the error on? my guess would be you have a numeric value for height or weight thats more then 999.99. Maybe missing decimal dot for weight?

Upvotes: 1

Related Questions