简体   繁体   中英

SQL Server 2008 insert Error

hikjhkjkjkjkjkjkjhkjhlkjkljlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjlkjl

You need to define a length for your varchar columns - otherwise, they will default to a length of 1 character!

CREATE TABLE GroovyExps_Src
    (EMPNO VARCHAR(25) Primary Key,
      ..... and so forth....

Also: is varchar really the most appropriate datatype for everything ?? If you have a empno - this sounds like a number - so you should use an INT or DECIMAL(p,s) - not a Varchar !!

Things like HireDate or BirthDate should also clearly be DATE columns - again: don't just use Varchar for everything out of lazyness - think about your data and pick the most appropriate datatype for each column!

VARCHAR will default to length of 1 unless you explicitly state what it should be. All the data you are trying to insert will be truncated to lengths of one character using your existing code.

By default "Varchar" datatype, define a single character value, if you not define any size.

So give or define the maximum size in varchar data-type to accept input data as @mark suggest.

When you give more than a single value to insert or update in that column, it gives the same error.

Even though, if you define varchar(100) means character accepted length should be 100 and when you try to insert or update the 101 length data, the same error you get.

The reason is Sqlserver not insert beyond the maximum limit which you define or default length( 1 character).

当您仅指定varchar ,其默认大小为1 ..因此,您可能不会插入正确的数据。.您需要提及varchar(50)以便它具有足够的大小来保存数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM