Search code examples
sql-serverzerotruncation

How should I insert values into table with out truncation of zeros in SQL Server


I got a table EMPLOYEE1 and i'm trying to insert values into it

INSERT INTO EMPLOYEE1 values(00001, 00004566)

But it inserts the values as 1 and 4566 truncating zero's why does this happen. can some one help me out


Solution

  • This is happening because the data type of this column is numeric. You should make these columns varchar to be able to insert numbers without trancating zeros. Something like:

    CREATE TABLE Employee1(EmpNumber VARCHAR(50), EmpName VARCHAR(50), ...);
    
    INSERT INTO Employee1 VALUES
    ('00001', 'Foo', ..);