Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Unanswered: Changing table column size

    I'm new to mssql.

    I need to change the size of a column of a table from char(255) to char(500). I used the line:

    alter table table_name alter column column_name char(500)

    When I run that command, I get a message that it was sucessful. However, when I try to enter data into the changed column, the number of characters I can enter is still 255. I check the information schema for the column and the 'character_maximum_length' field is 500.

    What is the problem here? Is the maximum allowable length for char 255? How can I get a column to have 500 characters?

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Really?

    Code:
    USE Northwind
    GO
    
    CREATE TABLE myTable99(Col1 char(250))
    GO
    
    INSERT INTO myTable99(Col1)
    SELECT REPLICATE('x',250) UNION ALL
    SELECT REPLICATE('x',25) UNION ALL
    SELECT REPLICATE('x',2)
    GO
    
    SELECT LEN(Col1) FROM myTable99
    GO
    
    -- Will Fail
    INSERT INTO myTable99(Col1)
    SELECT REPLICATE('x',500)
    GO
    
    ALTER TABLE myTable99 ALTER COLUMN Col1 char(500)
    GO
    
    INSERT INTO myTable99(Col1)
    SELECT REPLICATE('x',500)
    GO
    
    SELECT LEN(Col1) FROM myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    xiphias, you're probably testing the number of characters inserted by doing SELECT col_name FROM table. At this point you see only 255 characters, right? Check your QA settings (Tools/Options/Results/Maximum characters per column)

  4. #4
    Join Date
    Mar 2004
    Posts
    3
    Haha. That was the problem. I changed the settings and now I can see all the characters.

    Now I try to do queries with the database with PHP and the number of characters return from the query is 255 again. Is there some setting file that I have to change in PHP?

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Your's is an interface problem...has nothing to do with sql server...

    What's PHP?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Mar 2004
    Posts
    3
    Sorry, I didn't know what was wrong..

    PHP is a programming language for dynamic web pages. I guess I'll have to ask that in a different forum.

    Thanks for the help.

  7. #7
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    True, it seems you need to control from PHP point of view also.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

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