A lucky draw system [closed] - database

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am creating a lucky draw system whereby the participants' username will be stored in either a file or a database and later one of the username will be picked as the winner. Each product has many participants.
My question is what would be the best way to store the usernames? Should I use a text file with each username separated as username\n ? Should I store the usernames in a field (type text) separated by comma? Or should create a participant table that links the member table and product table?

The best way will be to use a database due to the following reasons
1.Data of such apps may grow beyond control and file ops will take significant time then.
2.Databases ensure easy usage of the data stored,rather than file.
3.Database allows adding of new attributes,which is costly beyond imagination if you use a file.For eg,You may need to add attributes like score to your username in future.
So I would recommend using a table.

Related

basic applications of data structure [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have to do a project for my college course in data structures using c and was wondering if anyone can tell me any real life uses of data structures so that I can base my project on it.
Please keep in mind that it is only my first year of programming in c so I currently do not have the skills to write very advanced code.
Since this is your first year of college, I wouldn't go into the depths of datastructures and their uses.
Simplest use of a data structure: A English-to-English Dictionary, which can be built using a Hash Table.
From here, you can go into depths of DS
Datastructures in OS design, such as memory manager (Linked List + Hash-Map),
BTrees in Database Design
Trees in Filesystems
Graphs in electronic circuit simulation, AI etc
many many more.
Well, data structures improve the logic or performance of manipulations on your data. To see the latter, you could try the following. Generate a list of a million or more random numbers and try to find one of them in particular.
Try comparing the performance of the following two representations: an array and a sorted binary tree.
There are lots of real usages of data structures, whether it's in your OS, in Databases, etc.
Think of the case of (not only) MySQL that uses B-Trees to manage records (http://dev.mysql.com/doc/refman/5.5/en/index-btree-hash.html).
Look at list of data structures from wikipedia. Most of the data structures have real world examples or applications section on their own description page.

What is the Need of Functions in database if Procedures can do all things [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What is the need of function in databse as everything that a function does, can also be achieved by Procedures in database.
In Oracle they are very similar. Principal difference is that function returns result, procedure doesn't. (Not to be confused with output parameters which is possible to have in both of them...)
This difference makes possible to use functions inside SQL statements like
select user_name, myFunction( some_attribute ) from ...
or
select ... where fn2(col1)=something
You can think of it as some kind of transformation.
Of course, for efficient use inside SQL statements, they should be fast, as can be executed many times for each line in output or each examined line. (And/or be sure that number of lines will not be too big).
Also, in recent versions is possible to use return as real time dbms_output (search for pipe row).
You can also use functions in function based indexes.
And these indexes can also be unique indexes.
With function based unique indexes you can build sophisticated unique constraints.
create unique index UK_MYINDEX
on TBL_MYTABLE (case when IS_ACTUAL(MY_COLUMN_2) then MY_COLUMN_1 end);
In this example I use the IS_ACTUAL function in a unique index in order to enforce the unique MY_COLUMN_1 constraint only on the actual records.

VARBINARY or BINARY for byte arrays of 250-1000 bytes? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have to create a table in a database and one of the fields will contain between 250 and 1000 bytes. When it comes to read-write performance, should I use VARBINARY or BINARY(1000)? Does it matter?
As per this Reference, you should be using varbinary. binary is for fixed length, and your requirement is a variable-length field.
As for performance, I don't know if there'd be a difference. The best way to find out would be to view the execution plan or run a trace to see performance. I would safely assume that it is similar performance and negligable difference, although I'd still use varbinary at least if only for the reason you have a variable length requirement.
EDIT: this post assumes SQL Server. Please clarify your RDBMS.
My first thought on this would be: Test it
If you could make some quick tables and load some data into them with the different datatypes then query off of that. I would think that would give you a pretty good indication of which would be the better to use.
Sorry i don't have any concrete data to give you on performance, but i think that would be a fairly legit test for the answer. I'm interested in your results if you decide to go that route :)

Once I delete an object from an array, I need to delete it from another array at the same time. How? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Ive got an app containing contact list, similar to Contacts application. I have all the objects in an array, but I have another array for favourite contacts, which is displayed in another tab. The problem is that once I delete an objects from my contacts array, it stays in the favourites array. Any ideas how can this be solved? It would help a lot. Thanks
As the comments said, your language and array structure would be useful, but I'll try and answer from a "algorithm" perspective.
Your "Favourites" should contain the same objects as in your Contact list (and I assume that object has an ID. If it doesn't, put one in). From there you can say "if I delete from Favourites, simply remove that object from the array". Otherwise, "if I delete from the 'Contacts list' then iteratively remove all the equivalent objects from the other arrays".
Alternatively, if your "Favourites" array simply holds the ID of the contact (and to display it you retrieve the object from the Contact list), then similarly you can delete the number.
Hope this helps, and when you clarify your question more, I'm sure someone will give you a more efficient answer ;)

How to create a symbol table? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Can I use malloc to add symbol table entries? How do I traverse the table to check if something is already there?
A "symbol table" doesn't describe a particular kind of data structure. It merely describes the primary modes of operation: adding symbols and retrieving symbols by name. Symbols here are basically attributed names. For a compiler class, one such an attribute could be IsAFunction.
C has very few built-in datastructures. You'd have to create one yourself in this case. In C++, it would just be a matter of a std::map<std::string, Attributes>. Now presumably if you're in a compiler class, you should already know how to implement datastructures in C (including the use of malloc()). If not, then a compiler class really isn't for you.
In general, symbol tables are implemented through hash tables. Hash tables have the advantage of O(1) store and retrieve, but they don't store data sequentially.
Assuming you're working in C you can uses malloc(), but it requires more work than that. The provided link should enlighten you.
I'v done that with a double chained linked list before. But now i will definitively do it with a hashtable.
It's just a datastructure.

Resources