CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    2

    Copy row with unique constraint

    Hi,
    I am trying to add a new user to the MySQL database.
    1) I am trying to add a new user. The mysql.user table has a lot of columns.
    Whilst I could just insert specifying the Host & User fields, how would I copy a row, change a value or two and insert the updated row without having to specify all the columns.
    For example how would I copy a row and insert that row where one or more columns has a unique constraint without having to name all the columns?

    2) How do I get to see the 'mysql' database in MySQL Workbench?

  2. #2
    Join Date
    Sep 2011
    Posts
    2

    Re: Copy row with unique constraint

    PS
    I should add that I know how to create a user.
    This question is really about what is the simplest way to copy & paste a row from a table with lots of columns and make some changes.

  3. #3
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Copy row with unique constraint

    About your first question, something like this should work:
    Code:
    INSERT INTO table (unq1, unq2, col3, col4, col5, ..., colN)
    SELECT 'xxx' AS unq1, 'xxx' AS unq2, col3, col4, col5, ..., colN
    FROM table WHERE ...;

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured