database

Should I use a Foreign Key to Show Tree Relationship in SQL

I am trying to model a tree relationship in a table. For instance, there are "Categories" and categories can themselves be inside a Parent category. My schema is: id int PRIMARY KEY, parent_id int, name My question is, should I label the parent_id column as a Foreign key? Foreign implies "outside" and not self-referencing. Is ther...

Ideas on database design for capturing audit trails

How can I maintain a log of the data in my DB? I have to maintain a log of every change made to each row. That means that I can't allow DELETE and UPDATE to be performed. How can I keep such a log? ...

MySQL - fetch rows where first character is not alphanumeric

I am adding a few new features to a small project i'm working on and one of them is alpha pagination which looks like # 0-9 A B C D E ... X Y Z I can easily fetch items by their first letter using something like SELECT * FROM ... WHERE name LIKE 'A%' ... Grouping everything that starts with a number and all other characters is a...

Calling PHP variables from inside a MySQL Database

I'm currently in the middle of working on a CMS system that builds the website straight from information saved in a MySQL database. Here's the problem I'm having: Inside the CMS the user enters coding for a template the frontend of the site (frontend.php) calls the variable where the layout is stored ($template_header) The frontend a...

HTML5 Database administration / introspection?

I'm playing around with html client side storage and wanted to know if there are any facilities for introspection of the database - is there an equivalent of sqlite ".tables" or ".schema" ? Also, I'm not seeing my tables show up in AppData\Local\Apple Computer\Safari\LocalStorage . Is there another place tables are stored? ...

How do I store a rating in a song?

I want to be able to store information about a song that has been opened using my application. I would like for the user to be able to give the song a rating and this rating be loaded every time the users opens that file using my application. I also need to know weather I should store the ratings in a database or an xml file. ...

How to write a simple database engine

I am interested in learning how a database engine works (i.e. the internals of it). I know most of the basic data structures taught in CS (trees, hash tables, lists, etc.) as well as a pretty good understanding of compiler theory (and have implemented a very simple interpreter) but I don't understand how to go about writing a database e...

Which file based DBMS should I support in an open source project?

I am working on an open source project which can use a number of DBMS' as backend. So far we supports SQL Server 2005 and SQL Server 2008 but we would also like to support some additional databases including some file based DBs. Note: The file based databases must work on a 64-bit platform, so MS Access is not an option as there is no 6...

Are less tables better than more?

I'm implementing a small time tracking app and I can't decide between two database designs. The first has all the log entries in a single table, ie. TimeLog ------------- job_id : long timestamp start : boolean [or perhaps 'type : enum'] _id : long The other option is to have two tables, one for 'start' entries the other...

Best way to store password in database

I am working on a project that has to have authentication (user name/pass) It also connects to a database so i figured i would store the user name and password there but it seems like not such a good idea to have passwords as just a text field in a table sitting on the db I'm using C# and connecting to a 2008 express server. can anyon...

MySQL Question - How to handle multiple types of users - one table or multiple?

Hey everyone, I'm designing a database for an organization that has multiple "types" of users. At first, I created only one user table. However, while all users share some common information (first name, last name, username, password, etc.), each user type requires one or two additional fields that are not applicable to all users. While...

Gracefully closing multithreading application?

I have an application that has two threads. The first one (the main thread) that captures the data using socket and update DataTables The second Inserts the DataTables into the database. The application works fine but when it closes, the main thread finishes reading the data and call Abort method in the second thread, which may be ins...

Continue after primary key violation error

The problem is during inserting data from staging table during import routine. The system is a legacy one I inherited, and short term while I develop something more suitable I want to patch things to avoid the data transfer failing. Unfortunately the facility exists via another application to create an entry into table, called CommRece...

Need advice for large .net data access layer

Hi all, Starting up a new project it is 100% new development against a very large (300 tables) legacy database. The database does not match up all that well to the business model so my initial thoughts where to use a ORM. I got a proof of concept working with NHibernate pretty well... but got A LOT of management push back on the use ...

How can I define a type in oracle11g that references a collection of that type?

I want to do something like this create type Item as object ( id number, subitems table of ref Item ) but oracle throws an exception when I try to do it. Is this possible, and if yes then how? ...

Unable to make a MySQL database of SO questions by Python

Brent's answer suggests me that has made a database of SO questions such that he can fast analyze the questions. I am interested in making a similar database by MySQL such that I can practice MySQL with similar queries as Brent. The database should include at the least the following fields (I am guessing here, since the API of SO's api...

Need an embedded/In Memory Database

Hi all, I need an embedded/In Memory Database which support multithread access. Thanks! Leo ...

Can I download an SQLite db on /sdcard and access it from my Android app?

I already found out that there is no way to bundle files in an .apk and have them on /sdcard, the best option so far being to download the large files upon first run. I came accross a tutorial saying how to bundle an sqlite db with the apk and then copy it so that it can be accessed with SQLiteDatabase (thus doubling the space needed, an...

Efficient SQL 2000 Query for Selecting Preferred Candy

(I wish I could have come up with a more descriptive title... suggest one or edit this post if you can name the type of query I'm asking about) Database: SQL Server 2000 Sample Data (assume 500,000 rows): Name Candy PreferenceFactor Jim Chocolate 1.0 Brad Lemon Drop .9 Brad Chocolate .1 Chris Chocolate .5 Ch...

How to build a DataBase Miner ?

Hi everybody Has everybody here ever built a DB Miner? If you have ever built a DB Miner then can you give some sort of knowledge of how to build one or suggest me some books that i should read in preparing for it. Cause i'm trying to build a DB Miner but i stuck in what to begin. Thank you ! ...