relational-database

Why does referencing a SQLite rowid cause foreign key mismatch?

谁说我不能喝 提交于 2019-12-01 15:23:48
SQLite version 3.7.9 2011-11-01 00:52:41 sqlite> PRAGMA foreign_keys = 1; sqlite> CREATE TABLE foo(name); sqlite> CREATE TABLE bar(foo_rowid REFERENCES foo(rowid)); sqlite> INSERT INTO foo VALUES('baz'); sqlite> SELECT rowid, name FROM foo; 1|baz sqlite> INSERT INTO bar (foo_rowid) VALUES (1); Error: foreign key mismatch Why does this error occur? It is a DML error , but I don't know what's wrong because: foo exists. foo.rowid exists. foo.rowid is the primary key of foo and therefore constrained to uniqueness. bar.foo_rowid is one column, which matches the fact that foo.rowid is one column.

How to provide relational algebra for the given schema?

风流意气都作罢 提交于 2019-12-01 15:01:07
EMPLOYEE(PERSONNAME, STREET, CITY) WORKS(PERSONNAME,COMPANYNAME, SALARY) COMPANY(COMPANYNAME, CITY) MANAGES(PERSONNAME, MANAGERNAME) Find the names of all employees in this database who do not work for First Bank Corporation (assuming that all people work for exactly one company and people are allowed to appear in the database (e.g. in employee) but not appear in works). Here I do not understand the assumption part. What does it actually mean ? As @wildplasser pointed out: The first part of the assumption assuming that all people work for exactly one company... declares the case that there is

How do I know which is the more appropriate database design? (Authors, Articles & Comments)

不打扰是莪最后的温柔 提交于 2019-12-01 14:55:42
Let's assume a database with three tables: Author , Articles , Comments Assuming the relationship is as follows: Author has many Articles Article belongs to one Author Article has many Comments Comment belongs to one Article If I want to know which Author writes the most commented article, I need to select all Articles that belong to a specific Author first. Then I can count the number of comments that were posted under each of those articles. Which in general leads to more complex queries. If The relationships were as follows: Author has many Articles Article belongs to one Author Article has

Are There Bidirectional Relational Databases?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 14:54:13
I'd like to create a clothing database, where items from tables such as 'tops' or 'bottoms' (pants, skirts) can be matched with each other and with items in other tables such as hats or shoes. I want to be able to relate all tables to each other in both directions (each skirt goes with many tops, and each top goes with many pants, etc) and I want each table to be related to each other. E.g, I want to query 'what items look good with these pants' and see a list of shirts, shoes, etc. Using a relational database would requires in-between tables for every relationship, which creates a ridiculous

Why does referencing a SQLite rowid cause foreign key mismatch?

好久不见. 提交于 2019-12-01 14:18:37
问题 SQLite version 3.7.9 2011-11-01 00:52:41 sqlite> PRAGMA foreign_keys = 1; sqlite> CREATE TABLE foo(name); sqlite> CREATE TABLE bar(foo_rowid REFERENCES foo(rowid)); sqlite> INSERT INTO foo VALUES('baz'); sqlite> SELECT rowid, name FROM foo; 1|baz sqlite> INSERT INTO bar (foo_rowid) VALUES (1); Error: foreign key mismatch Why does this error occur? It is a DML error, but I don't know what's wrong because: foo exists. foo.rowid exists. foo.rowid is the primary key of foo and therefore

Applying column permissions for a table over a trigger

人盡茶涼 提交于 2019-12-01 14:17:14
For now, i have a table called members, which contains stuff, which is splitted in conact datas, bank datas.... Now, the admin should be able to create, update, delete users, which are saved in another table, which can only access the administrator. The users should get their own mysql user account and the admins should also be able to set permissions, like that users arent able to access bank datas. For now, I made a trigger, which creates and deletes the user accounts. Now I wanted to apply the permissions over a trigger, but I didnt find a promising solution I tought already about setting

MySQL wrong results with GROUP BY and ORDER BY

↘锁芯ラ 提交于 2019-12-01 13:32:07
I have a table user_comission_configuration_history and I need to select the last Comissions configuration from a user_id . Tuples: I'm trying with many queries, but, the results are wrong. My last SQL: SELECT * FROM( SELECT * FROM user_comission_configuration_history ORDER BY on_date DESC ) AS ordered_history WHERE user_id = 408002 GROUP BY comission_id The result of above query is: But, the correct result is: id user_id comission_id value type on_date 24 408002 12 0,01 PERCENTUAL 2014-07-23 10:45:42 23 408002 4 0,03 CURRENCY 2014-07-23 10:45:41 21 408002 6 0,015 PERCENTUAL 2014-07-23 10:45

Determining if a relation is 1NF with no data

白昼怎懂夜的黑 提交于 2019-12-01 13:24:36
问题 I have a relation CAR_SALE(Car#, Date_sold, Salesperson#, Commission%, Discount_amt) Primary Key: {Car#, Salesperson#} Additional Dependencies: Date_sold -> Discount_amt Salesperson# -> Commission% and I have to determine if it is in 1NF, 2NF, or 3NF. We are only given the relation schema with no data. I am having trouble determining if this is in 1NF. In order for something to be in 1NF, it must not have repeating groups for an attribute. Given this relation schema with no actual data,

How do I know which is the more appropriate database design? (Authors, Articles & Comments)

百般思念 提交于 2019-12-01 13:15:59
问题 Let's assume a database with three tables: Author , Articles , Comments Assuming the relationship is as follows: Author has many Articles Article belongs to one Author Article has many Comments Comment belongs to one Article If I want to know which Author writes the most commented article, I need to select all Articles that belong to a specific Author first. Then I can count the number of comments that were posted under each of those articles. Which in general leads to more complex queries.

When should a social security number be used as a database primary key?

情到浓时终转凉″ 提交于 2019-12-01 12:49:43
Our DBA says that because the social security number (SSN) is unique, that we should use it as the primary key in a table. While I do not agree with the DBA (and have already mentioned some of the good parts found in this answer ), are there any situations where he could possibly be correct? SSN is not a unique identifier for people. Whether it should be the PK in some table depends on what the rows in the table mean. (See also sqlvogel's answer .) 6.1 percent of Americans have at least two SSNs associated with their name. More than 100,000 Americans have five or more SSNs associated with