Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-13-2003, 09:14 PM   #1
Registered: Mar 2003
Posts: 65

Rep: Reputation: 15
how to ensure only one record exist with the same name.


Could some one tell me how to ensure that only one record with the same name exits. i have a table called imageinfo, with 4 columns, image_id, image_name, image_size and image_date.

I would like to ensure that only one record exist with the same name.


Old 03-13-2003, 09:20 PM   #2
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Not sure what you mean. Does this help?

struct table_t {
  char name [255];
  int id;
  int size;
  int date;

int main() {
  struct table_t imageinfo;
  return 0;

Last edited by GtkUser; 03-13-2003 at 09:21 PM.
Old 03-14-2003, 06:17 PM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
I think he was talking SQL .....
Old 03-14-2003, 07:00 PM   #4
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
I've never used SQL before, but I did play with Borland's Database Engine in Delphi a little.

So, aside from the brute force approach:
1) Read first record's filename
2) Look for a match in the rest of the database
3) Read second record's filename
4) Look for a match in the rest of the database
5) ...

There was an easier method in Borland:
1) Create a secondary index in the table based on the filename field (secondary indices do not need to contain only unique elements)
2) Sort the table based on this secondary index
3) Any duplicate filenames ought to be found consecutively when you walk through each record in the table

That assumes the filenames are case-sensitive (i.e. File1.img != file1.img).
Old 03-18-2003, 07:07 AM   #5
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,548

Rep: Reputation: 136Reputation: 136
1. SQL: u may make the column in the db "unique"
so the db will not allow a 2nd entry with the same value

2. if u manipulate data in a table using a programming language it would be useful to tell as which language u use, right?

i. e. there are different functions to retrieve the number of rows returned by a sql query

cheers, jens
Old 03-18-2003, 02:12 PM   #6
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
There's that marvelous thing in SQL called
an index, and one variant thereof supports
the feature unique ;)


P.S.: Once your database grows you'll
find that indexing also makes read access
much faster ;)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ensure that the complete development environment have been installed? Akhran Debian 3 08-16-2005 05:02 PM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 04:31 AM
how to ensure hdparrm settings are retained over a reboot? zero79 Debian 3 08-09-2004 04:15 PM
com ports, how do I find and ensure they are working Crasherz Linux - Newbie 1 04-09-2004 03:14 AM
pcfg_openfile: unable to check htaccess file, ensure it is readable andy18 Linux - General 4 08-21-2003 01:29 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration