What kind of data to accept any size?

Asked

Viewed 70 times

2

What kind of data can I use to store text "dynamically" in SQL Server?

I know that CHAR and VARCHAR are character data types, the difference is that CHAR is a type of data fixed length and VARCHAR is of variable length up to 255. I’m sure?

Now if I want to write a text of x characters larger than 255, which data type should I use?

  • 1

    Define "dynamic". VARCAHR accepts up to 2GB.

  • As Maniero said, really not only is 255 the varchar, 4000 already a very large value, but if you need more than this can use varchar(max)

  • if it’s dynamic I can only think of varchar

1 answer

2


If by dynamic you mean accept any size, the type VARCHAR is already what you want, and it allows you to specify a value from 1 up to 8000. If you do not specify anything the default is 8000 and not 255. But if you want more than this it can reach up to 2GB, just specify so:

VARCHAR(max)

I put in the Github for future reference.

When you do this the way the data is recorded changes a bit and can have performance implications. More can be seen in Difference between type text and type varchar in SQL Server.

Just note that this is the amount of bytes and not characters, there are encodings that a character can even have 4 bytes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.