Currently, I have a table column that has a text limit of 255 (Varchar[255]), I would like the number of characters increased to 4000 or more. What would the code be, if ran through a PHP page, to make this modification?
Note* - I have modified a column with a varchar(100)
to varchar(255)
, it seems that my columns cannot exceed a varchar
of 255
.
So far I have used this - alas, it doesn't work:
<?php
$dbhost = 's036';
$dbuser = 'rost';
$dbpass = 'rosword';
$conn=mssql_connect('smtscom','sTrsr','Rsa');
mssql_select_db('Gsa',$conn);
if(! $conn )
{
die('Could not connect: ' . mssql_get_last_message());
}
echo 'Connected successfully';
$sql = "ALTER TABLE new_tders2 ALTER
COLUMN description varchar(4000)";
mssql_select_db('Gsa');
$retval = mssql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table:');
}
echo "Table column modified successfully\n";
mssql_close($conn);
?>
When I run the PHP page (the code above), it says "Table column modified successfully", but I still can only input 255 characters into the column.
I figured it out - instead of using VARCHAR(4000)
, use TEXT
. It will exceed 4000
characters, and allow up to 64 Kb, 2 bytes overhead. However, this is fine in my case, as more than 4000 characters is fine for this part of the website.
Here is the new (working) code:
<?php
$dbhost = 's036';
$dbuser = 'rost';
$dbpass = 'rosword';
$conn=mssql_connect('smtscom','sTrsr','Rsa');
mssql_select_db('Gsa',$conn);
if(! $conn )
{
die('Could not connect: ' . mssql_get_last_message());
}
echo 'Connected successfully';
$sql = "ALTER TABLE new_tders2 ALTER
COLUMN description TEXT";
mssql_select_db('Gsa');
$retval = mssql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table:');
}
echo "Table column modified successfully\n";
mssql_close($conn);
?>
Thank you to all those that tried to answer.