Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Apr 2003
    Posts
    22
    Member #
    1060
    whats the code to add a row into and existing table on a mysql database, whats the sql query

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Code:
    INSERT INTO tablename (columnnames) VALUES (values);
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Junior Member
    Join Date
    Apr 2003
    Posts
    22
    Member #
    1060
    what do i put for values

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Depends on the data.

    Example:
    INSERT INTO tablename (columnName1, columnName2, ...) VALUES (value1, value2, ...);

    value1 goes into columnName1, value2 goes into columnName2, etc...

    EDIT: After talking to you on IM, it sounds like he wants to add a new variable column into the table. i.e. he already has columns 1 and 2, he would like to add a column 3. Not sure how to do this myself, but someone here might know.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  6. #5
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I got this straight out of MyPhpAdmin:

    Code:
    ALTER TABLE `dbName.`tableName` ADD `colName` TEXT NULL
    It seemed to work, give it a try.
    - Brian

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    EDIT: re-read the post... he DOES want DDL (Data Definition Language).

    dbName doesn't have to be explicitly mentioned, though.

    Here's a complete definition for adding a column.

    Code:
    ALTER TABLE [dbName.]tableName 
    ADD colName [dataType] [NULL | NOT NULL] [DEFAULT defaultValue]
    Where the elements in brackets [] are optional, and dataType can be integer, varchar, text, datetime, or whatever.

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    note... if you're going to add a NOT NULL column to a table, you MUST specify a DEFAULT value, or the operation will fail. Otherwise, you can first add the column to allow NULLs, then update it (UPDATE tableName SET columnName = '') and then alter it again not to allow nulls (ALTER TABLE tableName ALTER COLUMN columnName dataType NOT NULL)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:41 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com