relational-database

GUID / UUID for this scenario? Or compound key? Or other

£可爱£侵袭症+ 提交于 2019-12-12 15:22:51
问题 I'm currently working on a system that in some cases will need to run on a local database during the day, and then replicated to a central server during the night. It cannot all run from one central database as the local sites are out of contact with it periodically. The data at the central server is for viewing and reporting only at head office, so nothing needs to be reverse replicated back to the site. Each "site" is given a text based unique key (human generated). However, the thought of

Converting From NOT EXISTS to NOT IN

帅比萌擦擦* 提交于 2019-12-12 15:09:12
问题 I have three tables: sailor (sname, rating); boat (bname, color, rating); reservation (sname, bname, weekday, start, finish); In order to get a list of sailors who have reserved every red boat, I have: select s.sname from sailor s where not exists( select * from boat b where b.color = 'red' and not exists ( select * from reservation r where r.bname = b.bname and r.sname = s.sname)); I now need to rewrite this query with NOT IN instead of NOT EXISTS. Here's what I have so far: select s.sname

Database theory - relationship between two tables

岁酱吖の 提交于 2019-12-12 13:37:23
问题 I have a database with two tables - let's call them Foo and Bar. Each foo may be related to any number of bars, and each bar may be related to any number of foos. I want to be able to retrieve, with one query, the foos that are associated with a certain bar, and the bars that are associated with a certain foo. My question is, what is the best way of recording these relationships? Should I have a separate table with records of each relationship (e.g. two columns, foo and bar)? Should the foo

Migrate data from relational DB to NoSQL

南笙酒味 提交于 2019-12-12 11:05:39
问题 Is it possible/are there tools/ best practices etc to migrate data to a NoSQL format from a relational DB. I have a JEE6 app making use of Hibernate ORM to persist to MySQL but now we wish to move to NoSQL solution but need to bring the existing data with us Thanks W 回答1: There are some tools to help the migration, but in the end, MySQL is a relational database which has a completely different structure from noSQL databases. In the end, you will almost always have to do these four steps

How can I populate my database's all tables with random data?

馋奶兔 提交于 2019-12-12 10:55:16
问题 Is there such a software out there? It doesn't matter if the data itself make sense. I am just worried about the fields to get populated. Basically, it will read the table definitions and generate some data accordingly. It would also be great if it asks for how many rows to insert per table, whether the default values will be left blank or get populated, how to treat the varchars(to the full extent or up to a given,specified number of characters). Ideally free :) but commercial product

Natural join if no common attributes

匆匆过客 提交于 2019-12-12 08:22:43
问题 What will natural join return in relational algebra if tables don't have attributes with same names? Will it be null or the same as cross-product (Cartesian operator)? 回答1: If there are no attributes in common between two relations and you perform a natural join , it will return the cartesian product of the two relations. 回答2: A cartesian product of two tables will be returned.This is because when we perform any JOIN operation on two tables a cartesian product of those tables is performed and

Removing Mirrored Pairs from SQL Join

主宰稳场 提交于 2019-12-12 07:39:03
问题 I have a table with 2 fields (name, interest) and I want to find all pairs that have the same interest, with all duplicates and mirrored pairs removed. I am able to find all pairs and remove duplicates with the following SQL statement: SELECT P1.name AS name1, P2.name AS name2, P1.interest FROM Table AS P1, Table AS P2 WHERE P1.interest = P2.interest AND P1.name <> P2.name; But I am not sure how to remove mirrored pairs, ie: "wil","ben","databases" "ben","wil","databases" I tried to make the

Soft Delete vs. DB Archive

柔情痞子 提交于 2019-12-12 07:31:36
问题 Suggested Reading Similar: Are soft deletes a good idea? Good Article: http://weblogs.asp.net/fbouma/archive/2009/02/19/soft-deletes-are-bad-m-kay.aspx How I ended up here I strongly belive that when making software, anything done up front to minimize work later on pays off in truck loads. As such, I am trying to make sure when approaching my database schema and maintenance that it can maintain relational integrity while not being archaic or overly complex. This resulted in a sort of shudder

MySQL: Insert data into table, some data comes from another table (relational)

一曲冷凌霜 提交于 2019-12-12 04:56:30
问题 I want to run the following two queries in one: SELECT id FROM user_settings WHERE ...... $id = id_from_query_above(); $value = 100; // this could be anything INSERT INTO user_config (sid, value) VALUES($id, $value) ON DUPLICATE KEY UPDATE value=$value (notice that I want to update if a row associating to the primary key has already been inserted). 回答1: You want the insert . . . select syntax: INSERT INTO user_config(sid, value) SELECT id, $value FROM user_settings WHERE ...... ON DUPLICATE

How to insert data into a child table in mysql

社会主义新天地 提交于 2019-12-12 04:13:11
问题 I have 2 tables, an articles and a summaries table. The summaries table is a child of the articles table and I would like to add data into the summaries table through the articles table. The sql for the summaries table is as follows: CREATE TABLE summaries( summary_id INT NOT NULL AUTO_INCREMENT, article_id INT, summary TEXT, PRIMARY KEY(summary_id), FOREIGN KEY(article_id) REFERENCES articles(article_id) )ENGINE=INNODB; How do I add a summary into the summaries table and have the article_id