relational-database

SQLite many-to-many relationship?

梦想与她 提交于 2019-11-28 06:54:34
I'm trying to set up a SQLite3 database with foo s and bar s and a many-to-many relation between them. This is what I've got so far: CREATE TABLE foo( id INTEGER PRIMARY KEY NOT NULL, foo_col INTEGER NOT NULL ); CREATE TABLE bar( id INTEGER PRIMARY KEY NOT NULL, bar_col TEXT NOT NULL ); CREATE TABLE foobar( foo_id INTEGER, bar_id INTEGER, FOREIGN KEY(foo_id) REFERENCES foo(id) ON DELETE CASCADE, FOREIGN KEY(bar_id) REFERENCES bar(id) ON DELETE CASCADE ); CREATE INDEX fooindex ON foobar(foo_id); CREATE INDEX tagindex ON foobar(tag_id); ...but it doesn't seem to be working. I can delete a row

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

断了今生、忘了曾经 提交于 2019-11-28 03:05: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'?) 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 relational tables. Even with the assistance of proprietary extensions like Oracle's CONNECT BY , chasing down

MySQL table with a varchar column as foreign key

北城以北 提交于 2019-11-28 02:41:14
问题 I am trying to create a table with a varchar column as foreign key but MySql gives me an error while creating the table. My query is like this: CREATE TABLE network_classes ( id TINYINT(1) UNSIGNED NOT NULL AUTO_INCREMENT, category VARCHAR(80) NOT NULL, PRIMARY KEY(id), KEY `key_1` (`id`,`category`) ) ENGINE=InnoDB; CREATE TABLE networks ( id TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, category VARCHAR(80) NOT NULL, director_id TINYINT(3) UNSIGNED NULL, director

Foreign Key Referencing Multiple Tables

有些话、适合烂在心里 提交于 2019-11-28 01:57:10
问题 I have a column with a uniqueidentifier that can potentially reference one of four different tables. I have seen this done in two ways, but both seem like bad practice. First, I've seen a single ObjectID column without explicitly declaring it as a foreign key to a specific table. Then you can just shove any uniqueidentifier you want in it. This means you could potentially insert IDs from tables that are not part of the 4 tables I wanted. Second, because the data can come from four different

retrieve correct data from my schemas

假装没事ソ 提交于 2019-11-28 00:37:35
I would like to retrieve the Names of teachers who teach more than 1 course I am really stuck on how to do it , all I know is that I need to consider the Course schema and operate on it , could I get some advice in terms of pi(projection),sigma(condition),rho(rename) etc (not i any specific database language)? philipxy Since this is homework and you basically need to read & work through a textbook's absolutely introductory text & exercises on relational model basics & the relational algebra, I give some guiding questions tailored to your assignment. A relation (given or query result) comes

Core Data setting One-To-Many in XCode 4.3.1

落爺英雄遲暮 提交于 2019-11-28 00:15:13
问题 I'm trying to understand how to set up a one-to-many relationship in Xcode 4.3.1. Usually there was a Utilities pane with a "Plural" option, but I can't find it anymore. Does anyone know if this option was move somewhere else? Thank you :) 回答1: Guess that's what you are looking for: 来源: https://stackoverflow.com/questions/9933689/core-data-setting-one-to-many-in-xcode-4-3-1

Adding constraints in phpMyAdmin

家住魔仙堡 提交于 2019-11-27 23:16:27
问题 I feel like I'm being stupid, but I can't find anywhere on the phpMyAdmin interface to add constraints to foreign keys e.g. CASCADE ON DELETE I've looked for similar questions on here and on the phpMyAdmin wiki but I can't find anything about it. I realise I could do this via the query interface, but I'd like to know how to do it through the graphical interface. 回答1: First, you should have your storage engine as InnoDB. Then select a table and go to 'Structure' tab. Under the table you will

how are viewing permissions usually implemented in a relational database?

拈花ヽ惹草 提交于 2019-11-27 22:44:38
问题 What's the standard relational database idiom for setting permissions for items? Answers should be general; however, they should be able to be applied to example below. Anything flies: adding columns, adding another table—whatever as long as it works well. Application / Example Assume the Twitter database is extremely simple: we have one User table, which contains a login and user id; we have a Tweet table, which contains a tweet id, tweet text, and creator id; and we have a Follower table,

Opinions on sensor / reading / alert database design

孤者浪人 提交于 2019-11-27 22:30:11
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 UpperLimitValue LowerLimitValue [SensorReading] SensorReadingId Value Status Timestamp [SensorAlert]

Hierarchical Data - Nested Set Model: MySql

余生长醉 提交于 2019-11-27 18:20:46
问题 I am just learning how to implement the Nested Set Model but still have confusion with a certain aspect of it involving items that may be part of multiple categories. Given the example below that was pulled from HERE and mirrors many other examples I have come across... How do you avoid duplication in the DB when you add Apples since they are multi-colored (i.e. Red, Yellow, Green)? 回答1: You do not avoid duplications and the apple (or a reference to the apple) will be placed twice in your