Results 1 to 8 of 8

Thread: [varchar] (100) and empty space

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    [varchar] (100) and empty space

    Hello

    I am creating the following table

    CREATE TABLE [dbo].[myT] (
    [name] [varchar] (100) NULL
    )


    if I do

    INSERT INTO myT (name) VALUES ('A')

    i get in the table a column with

    A ...

    the 100 char place is full even if there is a data with only 1 char

    how is it possible to avoid it ?
    I want 100 char maximum but not full with nothing


    thank you for helping

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    On which rdbms? How do you know it uses 100 bytes?

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    run this command

    select datalength(name) from myT

  4. #4
    Join Date
    Apr 2006
    Posts
    178
    I am getting 200
    2 time the normal size !

  5. #5
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    r u sure you are querying the right table?
    This is what i got

    CREATE TABLE [dbo].[myT] ([name] [varchar] (100) NULL )

    INSERT INTO myT (name) VALUES ('A')

    select datalength(name) from myT
    --result 1

  6. #6
    Join Date
    Apr 2006
    Posts
    178
    sorry ! that field is nvarchar and I get 200 for [name] [nvarchar] (100) NULL

    if i run the code

    CREATE TABLE [dbo].[myT] ([name] [varchar] (100) NULL )

    INSERT INTO myT (name) VALUES ('A')

    select datalength(name) from myT


    i get also 1

    but I don't understand from where are coming in my table the blanks char
    each column = any(----------long space-------)

    the datalength allways= 100
    Last edited by anselme; 05-22-2007 at 02:46 PM.

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    Double check your table schema and how inserted values.

  8. #8
    Join Date
    Apr 2006
    Posts
    178
    I have inserted values with a @parameter char(100) !

    :-(

    now it works
    thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •