SQL statement to add field to a table

  • Can someone show me an example of how to add a field to a table using a SQL statement using the SQL web admin?

    I promise I'll only ask once, it will work for all fields/tables right?


    Kindest Regards,

    Jon
    Free Cell Phone Games

  • ALTER TABLE TableName ADD

    NewColName /*datatype*/int /*null or not null, null is the default*/not null /*only if you need a default value*/ default(0)

    GO

  • Should these 2 lines work by themselves?

    ALTER TABLE tblAccount ADD

    [MailServer] varchar(50)

     

    P.S. I forgoit i already had a post about this, I was going to delete this thread, but you had already replied.


    Kindest Regards,

    Jon
    Free Cell Phone Games

  • I don't see why they wouldn't,

    but I'd go with this :

    ALTER TABLE tblAccount ADD

    [MailServer] varchar(50) null -- just to make it obvious that the column will accept nulls.

    BTW MailServer doesn't need to be in brackets. If it does, it means it's a reserved keyword and another name should be used (for best practice).

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply