How to alter or change column with ALTER TABLE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • terenceyuen
    New Member
    • May 2007
    • 3

    How to alter or change column with ALTER TABLE

    I would like to change the type of Null to NO ,what is the command for this?
    I've tried this one, but no luck to get it work.
    ALTER TABLE claims_summary ALTER COLUMN advance_call_de tails SET NOT NULL;

    Thanks.
    Terence
    +----------------------+--------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +----------------------+--------------+------+-----+---------+-------+
    | client_id | int(11) | | | 0 | |
    | client_code | varchar(30) | | PRI | | |
    | club_id | int(11) | | | 0 | |
    | club_code | varchar(30) | | PRI | | |
    | yearclaim | int(10) | | PRI | 0 | |
    | advance_call | double(16,4) | YES | | 0.0000 | |
    | additional_call | double(16,4) | YES | | 0.0000 | |
    | supplementary_c all | double(16,4) | YES | | 0.0000 | |
    | release_call | double(16,4) | YES | | 0.0000 | |
    | advance_call_de tails | varchar(240) | YES | | | |
    +----------------------+--------------+------+-----+---------+-------+
  • tashy
    New Member
    • Oct 2006
    • 10

    #2
    Try this ALTER TABLE table name ALTER COLUMN column name data type NOT NULL


    By data type ,it could either be int,bit,etc

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      When you change or alter a column, you are basically redefining it, so you have to provide a full definition of the column, not just the attributes you want to change (otherwise, how would MySQL know if you wanted to remove an attribute from a column?).

      P.S., Please surround your mysql output with CODE tags to make it easier to read next time. Thanks.

      Comment

      • terenceyuen
        New Member
        • May 2007
        • 3

        #4
        Thanks a lot
        , I'v tried, but it return the following errors at the end. Is it possible to define the datetype : varchar(240) ?

        mysql> ALTER TABLE claims_summary ALTER COLUMN advance_call_de tails varchar(240) NOT NULL;

        ERROR 1064: You have an error in your SQL syntax near 'varchar(240) NOT NULL' at line 1

        Comment

        • pradeep kaltari
          Recognized Expert New Member
          • May 2007
          • 102

          #5
          Originally posted by terenceyuen
          Thanks a lot
          , I'v tried, but it return the following errors at the end. Is it possible to define the datetype : varchar(240) ?

          mysql> ALTER TABLE claims_summary ALTER COLUMN advance_call_de tails varchar(240) NOT NULL;

          ERROR 1064: You have an error in your SQL syntax near 'varchar(240) NOT NULL' at line 1
          Hi,
          Try this:
          Code:
          ALTER TABLE table_name MODIFY COLUMN column_name VARCHAR(240) NOT NULL
          Regards,
          Pradeep

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Hi.

            If you also want to change the name of the column you can do this:
            [CODE=SQL]
            ALTER TABLE myTable
            CHANGE myCol
            newName dataType NOT NULL;
            [/CODE]

            Comment

            • terenceyuen
              New Member
              • May 2007
              • 3

              #7
              Thank you so much. It's very useful tips..

              Comment

              Working...