Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When increasing the size of VARCHAR column on a large table could there be any problems?

I'm using SQL Server 2008 and I need to make a VARCHAR field bigger, from (200 to 1200) on a table with about 500k rows. What I need to know is if there are any issues I have not considered.

I will be using this TSQL statement:

ALTER TABLE MyTable ALTER COLUMN [MyColumn] VARCHAR(1200) 

I've already tried it on a copy of the data and this statement had no ill effects that I could see.

So are there any possible problems from doing this that I may not have considered?

By the way, the column is not indexed.

like image 201
Paul T Davies Avatar asked Sep 22 '11 10:09

Paul T Davies


People also ask

Does VARCHAR length affect performance?

Declared varchar column length will not affect the physical (on-disk) or data cache storage. It will affect the performance of actually using that index.

What is the maximum size for VARCHAR?

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

Does VARCHAR max waste space?

Even using varchar(max) shouldn't have any impact on storage.

Does VARCHAR size matter SQL Server?

Yes, is matter when you indexing multiple columns. Prefixes can be up to 1000 bytes long (767 bytes for InnoDB tables). Note that prefix limits are measured in bytes, whereas the prefix length in CREATE TABLE statements is interpreted as number of characters.

How to increase the size of A varchar column in SQL?

The name column is of datatype varchar and size 5. To increase the size of the column, we shall run the following SQL Query. ALTER TABLE students MODIFY name VARCHAR(30); Now, let us see the modified schema if the column size has updated. The column size has been successfully updated to the new value. Previous Next .

How to increase the size of the column in the table?

To increase the size of the column, we shall run the following SQL Query. ALTER TABLE students MODIFY name VARCHAR(30); Now, let us see the modified schema if the column size has updated. The column size has been successfully updated to the new value. Previous Next .

Why can't I convert a column to VARCHAR (MAX)?

Another reason why you should avoid converting the column to varchar (max) is because you cannot create an index on a varchar (max) column. In my case alter column was not working so one can use 'Modify' command, like: alter table [table_name] MODIFY column [column_name] varchar (1200);

How to increase the size of a column in a schema?

Let us consider students table with the following schema. The name column is of datatype varchar and size 5. To increase the size of the column, we shall run the following SQL Query. Now, let us see the modified schema if the column size has updated. The column size has been successfully updated to the new value.


1 Answers

This is a metadata change only: it is quick.

An observation: specify NULL or NOT NULL explicitly to avoid "accidents" if one of the SET ANSI_xx settings are different eg run in osql not SSMS for some reason

like image 162
gbn Avatar answered Oct 13 '22 06:10

gbn