relational-database

When shouldn't you use a relational database? [closed]

梦想的初衷 提交于 2019-11-27 00:00:38
问题 Apart from the google/bigtable scenario, when shouldn't you use a relational database? Why not, and what should you use? (did you learn 'the hard way'?) 回答1: In my experience, you shouldn't use a relational database when any one of these criteria are true: your data is structured as a hierarchy or a graph (network) of arbitrary depth, the typical access pattern emphasizes reading over writing, or there’s no requirement for ad-hoc queries. Deep hierarchies and graphs do not translate well to

How can I find MAX with relational algebra?

大城市里の小女人 提交于 2019-11-26 23:52:19
Working with databases, how can I find MAX using relational algebra? Assuming you have a relation, A, with a single attribute, 'a' (reducing a more complex relation to this is a simple task in relational algebra, I'm sure you got this far), so now you want to find the maximum value in A. One way to do it is to find the cross product of A with itself, be sure to rename 'a' so your new relation has attributes with distinct names. for example: (rename 'a' as 'a1') X (rename 'a' as 'a2') now select 'a1' < 'a2', the resulting relation will have all values except the maximum. To get the max simply

Why use multiple columns as primary keys (composite primary key)

孤人 提交于 2019-11-26 23:49:26
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) ) My understanding is that both columns together ( P_Id and LastName ) represent a primary key for the table Persons . Is this correct? Why would someone want to use multiple columns as primary keys instead of a single column? How many columns can be used together as a primary key in a given table? MJB Your understanding is correct. You would do this in many cases. One

How to Implement Referential Integrity in Subtypes

痞子三分冷 提交于 2019-11-26 22:36:09
I have the following tables in a relational database: [Sensor] LocationId [PK / FK -> Location] SensorNo [PK] [AnalogSensor] LocationId [PK/FK -> Sensor] SensorNo [PK/FK -> Sensor] UpperLimit LowerLimit [SwitchSensor] LocationId [PK/FK -> Sensor] SensorNo [PK/FK -> Sensor] OnTimeLimit [Reading] LocationId [PK/FK -> Sensor] SensorNo [PK/FK -> Sensor] ReadingDtm [PK] [ReadingSwitch] LocationId [PK/FK -> Reading] SensorNo [PK/FK -> Reading] ReadingDtm [PK/FK -> Reading] Switch [ReadingValue] LocationId [PK/FK -> Reading] SensorNo [PK/FK -> Reading] ReadingDtm [PK/FK -> Reading] Value [Alert]

Database schema which can support specialized properties

一笑奈何 提交于 2019-11-26 22:03:01
I need to store a set of entities, of which there are several specialized versions. They have some common properties, but the specialized ones contain properties specific for that entity. Solutions The data store is a relational DBMS, and this is not for discussion :-) Specifically, it is the Microsoft SQL Server 2005. I could easily create a table for the common properties and then a table for each of the specialized versions. However, it is likely that new entities will have to be added to the solution later and I don't want to maintain both an object model and a database schema. Another

Pros/cons of document-based databases vs. relational databases

十年热恋 提交于 2019-11-26 21:16:31
I've been trying to see if I can accomplish some requirements with a document based database, in this case CouchDB. Two generic requirements: CRUD of entities with some fields which have unique index on it ecommerce web app like eBay ( better description here ). And I'm begining to think that a Document-based database isn't the best choice to address these requirements. Furthermore, I can't imagine a use for a Document based database (maybe my imagination is too limited). Can you explain to me if I am asking pears from an elm when I try to use a Document oriented database for these

Opinions on sensor / reading / alert database design

房东的猫 提交于 2019-11-26 21:07:13
问题 I've asked a few questions lately regarding database design, probably too many ;-) However I beleive I'm slowly getting to the heart of the matter with my design and am slowly boiling it down. I'm still wrestling with a couple of decisions regarding how "alerts" are stored in the database. In this system, an alert is an entity that must be acknowledged, acted upon, etc. Initially I related readings to alerts like this (very cut down) : - [Location] LocationId [Sensor] SensorId LocationId

Difference between 3NF and BCNF in simple terms (must be able to explain to an 8-year old)

最后都变了- 提交于 2019-11-26 19:15:00
I have read the quote : data depends on the key [1NF], the whole key [2NF] and nothing but the key [3NF] . However, I am having trouble understanding 3.5NF or BCNF as it's called. Here is what I understand : BCNF is stricter than 3NF left side of any FD in the table must be a superkey (or at least a candidate key) So why is it then, that some 3NF tables are not in BCNF? I mean, the 3NF quote explicitly says "nothing but the key" meaning that all attributes depend solely on the primary key. The primary key is, after all, a candidate key until it is chosen to be our primary key. If anything is

What are the uses for Cross Join?

那年仲夏 提交于 2019-11-26 18:54:07
问题 A cross join performs a cartesian product on the tuples of the two sets. SELECT * FROM Table1 CROSS JOIN Table2 Which circumstances render such an SQL operation particularly useful? 回答1: If you have a "grid" that you want to populate completely, like size and color information for a particular article of clothing: select size, color from sizes CROSS JOIN colors Maybe you want a table that contains a row for every minute in the day, and you want to use it to verify that a procedure has

Setting up table relations what do “Cascade”, “Set Null” and “Restrict” do?

巧了我就是萌 提交于 2019-11-26 18:52:59
问题 I want to start using table relations in a new project. After some googling I got 2 tables set up as InnoDB: The keys I want to link are ->users->userid (primary) ->sessions->userid (index) The only thing that I don't understand in this process is what the different settings for "On update" and "On delete" do The options here are: -- (nothing?) Cascade (???) Set Null (sets everything to null?) No action (well duh...) Restrict (???) I basically want the data in sessions to be deleted when a