database-design

SqlServer constrain field value dependent on another field value

As the question title, is there a way to do this? eg: DrivingLicence --------------- CanDriveCar (bool) CanDriveMotorbike (bool) CanDriveBus (bool) You can't drive a bus without a car licence, so I want the DB to throw an exception if anyone tries to give someone a bus licence when they haven't a car licence. ...

What is pctincrease in oracle?how the memory is allocated,resized,and autoextended while creating a table space

How the memory is allocated,reallocated and autoextended while creating tablespaces?what is meant by initial and default in tablespaces and how the next is a multiple of five times DB_BLOCK_SIZE? ...

Single column/primary key only table for referential integrity?

Maybe i'm going about this wrong but my working on a database design for one of my projects. I have an entity with a classification column which groups up entities into convenient categories for the user. These classifications are predefined and unchangeable by the user (at least thats the current design). I'm trying to decide if I sh...

How would you implement these queries efficiently in MongoDB?

Links have one or more tags, so at first it might seem natural to embed the tags: link = { title: 'How would you implement these queries efficiently in MongoDB?' url: 'http://stackoverflow.com/questions/3720972' tags: ['ruby', 'mongodb', 'database-schema', 'database-design', 'nosql']} How would these queries be imple...

Data Warehousing arbitrary fields

In our application, we support user-written plugins. Those plugins generate data of various types (int, float, str, or datetime), and those data are labeled with bunches of meta-data (user, current directory, etc.) as well as three free-text fields (MetricName, Var1, Var2) . Now we have several years of this data, and I'm trying to des...

Coding a cart: When the user checks out, should I copy every piece of product data into an "order product" table to save its state?

Should I clone the entire product along with all related data into another table for posterity, effectively logging the current state of the product, as it was when the user purchased it? Pros: The product (as the user saw it when it was purchased) is held for posterity and never changed. If the product data changes over time, it won...

How do I re-use reports on different datasets?

What is the best way to re-use reports on different tables / datasets? I have a number of reports built in BIRT, which get their data from a flat (un-normalized) MySQL table, the data which in turn has been imported from an excel sheet. In BIRT, I've constructed my query like this, such that I can change the field names and re-use the ...

Help with complex join conditions

I have the following mysql table schema: SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `network` -- -- -------------------------------------------------------- -- -- Table structure for table `contexts` -- CREATE TABLE IF NOT EXISTS `contexts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `keyword` varchar(255) NOT NULL, PRI...

Database Design: ordered many-to-many relationship

In Django, I have the following models: class Pink(models.Model): ... class White(models.Model): ... pinks = models.ManyToManyField(Pink) ... At some point, I needed to define an ordering of Pinks inside a White (in order to have White1.pinks: P1, P2, P3 instead of a random White1.pinks: P2, P3, P1), so I've created ...

DB Schema for Facebook like Wall + "Shared links"

Hi, I am making a db schema for facebook like wall structure. I need to save wall posts, share a link, share a video stuff into my database. Till now I am able to make this schema : GO CREATE TABLE [Wall] ( [ID] [int] NOT NULL IDENTITY(1, 1) , [PostText] [nvarchar](MAX) [PostedByUserID] [int] NULL , [PostedO...

like stackoverflow questions tags,how to design it in databases?

i has 3 plans: 1, in questions table: question ------------------------------------ id title content ... tags ------------------------------------ 1 aaa bbb ... tag1,tag2,tag3 (use , to split more tags) 2, in tags table and split: tags ------------------------------------ id tag --------------------------...

How to store bidirectional relationships

I am writing some code to find duplicate customer details in a database. I'll be using Levenshtein distance. However, I am not sure how to store the relationships. I use databases all the time but have never come accross this situation and wondered if someone could point me in the right direction. What confuses me is how to store the...

T-SQL. Still need an identity value from SuperType table although there are no values to insert

Hello. Rightly or wrongly I’m dealing with a generalised SuperType table which I have the sub type data for but not the SuperType data. However to insert the SubType data I obviously need the Identity ID from the SuperType table first. I was wondering if anyone else has come across this and how they got around it. Unfortunately there...

Primary and foreign key

Can we apply two primary keys in a table in anyway? ...

Best primary key for storing URLs

Hello, which is the best primary key to store website address and page URLs? To avoid the use of autoincremental id (which is not really tied to the data), I designed the schema with the use of a SHA1 signature of the URL as primary key. This approach is useful in many ways: for example I don't need to read the last_id from the databa...

How to insert arrays into a database?

In my previous question a lot of users wanted me to give some more data to toy with. So I got working on exporting all my data and processing it with Python, but then I realized: where do I leave all this data? Well I decided the best thing would be to stick them in a database, so at least I don't have to parse the raw files every time...

Associating notes with different entities in a database

At my job, we have judges perform a variety of tasks, e.g., rate movies or compare two pieces of text. We're in the process of designing a new database to hold all our data (we have some data already, but the database it's in is pretty hack), and I'm starting to build a Rails analytics application that will serve as a dashboard on these...

Datawarehouse Fact table question

I have a fact table called Loans. In this table in a loan identifier, the date the loan was made, and the amount of the loan. The business requirement I don't quite know how to do in the datawarehouse is the following. The loan amount can be adjusted in the future. So lets say August 1st we make a loan with an id of 1 and a amount ...

What makes this database's cascading deletes cyclical?

Vendor (PK) - Id Name Stand (PK) - Id VendorId - fk - cascaded delete if Vendor is deleted) Name Item (PK) - Id VendorId - (fk - cascaded delete if Vendor is deleted) Name Price UnavailableItem (PK) - ItemId - (fk - cascaded delete if Item is deleted) (PK) - StandId - (fk - cascaded delete if Stand is deleted) The database above repr...

Mysql: limits on table count, rows, and such

I'm working on a social network. From what I've gathered, there's a limit at 1792 for number of tables in a mysql cluster. I will probably end up with 100-200 tables for now. Is this reasonable/acceptable? Or is my db schema horrible like this? What is reasonable for a large scale project such as a social network? Also, what then is t...