Msg 8152, Level 16, State 14, Line 1 String or binary data would be truncated. The statement has been terminated. MY QUERY IS: `insert into department2 (department_id,department_name) values(1,'mec')` MY TABLE IS: create table department2 ( department_id int (10), department_name varchar (20), ) how do i remove this error?
Can you please execute this code and tell us the results ... IF OBJECT_ID('department2_test') > 0 DROP TABLE department2_test go CREATE TABLE department2_test ( department_id INT , department_name VARCHAR(20), ) go INSERT INTO department2_test ( department_id, department_name ) VALUES ( 1, 'mec' ) go SELECT [d].[department_id] , [d].[department_name] FROM department2_test AS d go DROP TABLE department2_test
The error indicates that the data is too big for the field. Either the code you have posted is incorrect - as that INSERT on that table would be fine - or you have a trigger on the table that is trying to do something else here.
Is the table created with the DBO schema and are your login assigned to the DBO as your default schema? If there are other tables with same name but different schema then you are depending on your default schema. Try to schema qualify your code.