Allocation memory for a variable...

  • When is allocate memory for a variable in a Script T-SQL?

    In the DECLARE instruction?

    Or in the SET education?

    Please, What is the difference between the CHAR() datatype and the the VARCHAR() datatype?

    How is allocate the memory for the two datatype?

    Thanks!!

    Ciao da Flavio

    PS

    Please, excuse me for possible grammar mistakes

  • Char is spacepadded, varchar is variable length.

    IF you use datalength function of @CharType char(10) it will always return 10, if you use same variable declared as varchar(10) and the value of the variable is "Hello" it will return 5

    Here is a sample:

    Declare @dude char(10)

    Declare @dude2 varchar(10)

    SET @dude = ''

    SET @dude2 = ''

    PRINT DataLength(@dude)

    PRINT DataLength(@dude2)

    quote:


    When is allocate memory for a variable in a Script T-SQL?

    In the DECLARE instruction?

    Or in the SET education?

    Please, What is the difference between the CHAR() datatype and the the VARCHAR() datatype?

    How is allocate the memory for the two datatype?

    Thanks!!

    Ciao da Flavio

    PS

    Please, excuse me for possible grammar mistakes


  • Memory is allocated when a variable is declared and the data is altered when it is set.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Oh yeah I forgot to mention if you have not assigned default value to a variable, and it contains a null value the datalength will be zero.

  • And also varchar() takes a little more memory than char() when char(n) column doesn't allow nulls (because there is no need to register the actual size).

    In variables, they use the same amount of memory but have different behavior.

    quote:


    When is allocate memory for a variable in a Script T-SQL?

    In the DECLARE instruction?

    Or in the SET education?

    Please, What is the difference between the CHAR() datatype and the the VARCHAR() datatype?

    How is allocate the memory for the two datatype?

    Thanks!!

    Ciao da Flavio

    PS

    Please, excuse me for possible grammar mistakes


Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply