SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: MySQL problem

  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Location
    Odense - Denmark
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Is there some way to have a unique key in a table? Like having this entry:
    (Unique_Key,2143,"This is goooood")

    and the Unique_Key specifices this entry uniquely.... For example the unique_key could be just the number of entries in the table at insertiontime. But is there a way to make MySQL find this key automatically when i insert a new post in the table?
    (you could do this "by hand" by counting the entries in the table before you do the insertion, but Im kinda lazy. And you proberly get into all kinds of problems with "consistency". Ie. you have to lock the database when doing this.)

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello madsen
    these are excerpts I got from mysql.com I recommend you to visit their site They have nice documentations.
    you can have a field definition in y our table create in mysql like

    col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [PRIMARY KEY]

    [AUTO_INCREMENT] [PRIMARY KEY] are what you look for, One makes column unique and other one increments this by one(type is one of integer types).

    If you insert a record in a table containing a column that has the AUTO_INCREMENT attribute, you can get the most recently generated ID by calling the mysql_insert_id() function.


Bookmarks

Posting Permissions

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