Cannot insert values into my SQL table
This is my query:
CREATE TABLE [dbo].[Veiculos] ( [IDCar] INT IDENTITY (1, 1) NOT NULL, [Matricula] VARCHAR (8) NOT NULL, [Marca] VARCHAR (30) NULL, [Modelo] VARCHAR (30) NULL, [Cor] VARCHAR (15) NULL, [Cilindrada] INT NULL, [Estado] CHAR (1) NULL, [Preco] MONEY NULL, PRIMARY KEY CLUSTERED ([IDCar] ASC), UNIQUE NONCLUSTERED ([Matricula] ASC), CHECK ([Estado]='Usado' OR [Estado]='Novo') );
For some reason, whenever I try to add values directly into the table it gives me the following error :
"The data in row 1 was not committed
Error Source: .Net SqlCliente Data Provider.
Error Message: String or binary data would be truncated."
This is for a college project, I'm still a novice with SQL, any help would be very much appreciated.
One of your fields is not big enough to hold the data. check the length of strings or int values are bigger than the range allowed.
estadois defined as
char(1), but you are trying to put the value
Either put in a single character or redefine the column width. Given your
checkconstraint, you probably want
alter table [dbo].[Veiculos] alter column estado varchar(10);
I see two things
IDCar need to have a value
[Estado] CHAR (1)
but the value you are trying to enter is of length 4. Try yo update it in the following way
[Estado] CHAR (4)