database-design

What foreign keys to add in 1:N relationship - Logical Model

旧街凉风 提交于 2019-12-24 18:13:53
问题 I'm confused about marking down bidirectional 1:N relationship in a logical model. We have two tables: Employee and Department. Every employee "knows" what department he's working at and every department "knows" what employees work there - in other words a collection of Employee identifiers. From a formal point of view, do I mark this down by adding FK to both tables? |EMPLOYEE | |DEPARTMENT| |____________| |__________| |PK EMP_ID |>O------||-|PK DEPT_ID| |FK DEPT_ID | |FK EMP_ID | |NAME |

Modeling courses and pre-requisites in the database

非 Y 不嫁゛ 提交于 2019-12-24 17:25:54
问题 Basic scenario: I have students, courses, and course-requirements that need to be stored in the database. Anyone has any insight into the best way to store these and traverse course prerequisites? 1) Simple example: C: Math 100, prereq: none C: Math 150, prereq: none C: Math 200, prereq: Math 101, Math 150 Student A completed Math 100. How does one determine if he is eligible to take CS200 via database querying? 2) More complicated example: C: Chem 100, prereq: none C: Chem 200, prereq: Chem

How to store address in database

一世执手 提交于 2019-12-24 16:43:34
问题 I am developing a CRM application that stores some data on companies we work with. Such as for example: CEO name and physical address of their head office. I will often need to look up for companies located in particular city and then sort the search result by street name. I know that proper solution will most likely be something like an address column of the integer type, which will point to the address table, which itself will contain other columns like state, city, street, housing_number,

Alternate in access database [duplicate]

梦想与她 提交于 2019-12-24 16:35:11
问题 This question already has answers here : Upserting in MS-access (5 answers) Closed 4 years ago . I want to check whether a row exists or not before inserting a new one in Access 2007. I have the following working query in SQL Server but I'm having trouble converting it to Access. update category set name='hell' where categoryid=287 if @@rowcount=0 begin insert into category(categoryid,name,path,parentcategoryid,creationdate) values (287,'a','a',12,'') end 回答1: Try this update category set

Generally, are string (or varchar) fields used as join fields?

瘦欲@ 提交于 2019-12-24 16:03:35
问题 We have two tables. The first contains a name (varchar) field. The second contains a field that references the name field from the first table. This foreign key in the second table will be repeated for every row associated with that name. Is it generally discouraged to use a varchar/string field as a join between two tables? When is the best case where a string field can be used as a join field? 回答1: It's certainly possible to use a varchar as a key field (or simply something to join on). The

Exist and Not Exists Query Misunderstanding?

感情迁移 提交于 2019-12-24 15:55:39
问题 Consider the following schema of a product database: Parts (pid, pname) Suppliers (sid, sname) Catalog (sid, pid) sid in Catalog is a foreign key and references Suppliers and pid in Catalog is a foreign key and references the Parts table. (s1, p1) in Catalog table shows supplier s1 produces p1 . If I want find details of Parts that are not supplied by some suppliers, how we can do this? I read some parts as follows: SELECT * FROM parts P WHERE ....... (SELECT S.sid FROM suppliers WHERE .....

How do you determine functional dependencies and a primary key?

拜拜、爱过 提交于 2019-12-24 15:18:46
问题 In my Oracle Database Programming course, the first part of our final lab assessment requires that we: Identify the Primary Key of the table as it is currently shown Find all functional dependencies of the table which we are given to work with. Draw the dependency diagram for the table(s) The table is in 1NF to begin with. From the research I have done, it seems like I need to essentially combine every possible FD, which would not only consume a very large amount of time, but seems bizarre

Fill MySQL records one-to-many related tables in one action

心不动则不痛 提交于 2019-12-24 15:12:05
问题 I have two MySQL tables with an one-to-many relationship between them. For example: CREATE TABLE test1 ( pk1 INTEGER AUTO_INCREMENT PRIMARY KEY, testvalue1 INTEGER ); CREATE TABLE test2 ( pk2 INTEGER AUTO_INCREMENT PRIMARY KEY, testvalue2 VARCHAR(50), fk2 INTEGER NOT NULL, FOREIGN KEY (fk2) REFERENCES test1 (pk1) ); If I want to insert records in both tables I can first insert a record in the PK table (e.g. INSERT INTO test1 SET testvalue1=100 ), determine the PK value (e.g. SELECT MAX(pk1)

Django Permissions for Different Clients

依然范特西╮ 提交于 2019-12-24 14:28:24
问题 I'm working on a Django project which will take on firms as clients and each client will be allowed to create multiple users. These users can then be assigned different permissions or roles. The catch being that the type of permissions vary with clients i.e. they're not as simple as read, write, delete. Hence one client can have only 5-10 types of permissions while the other can have 100's. The inbuilt Django permissions framework does not directly support my usecase, so this is what I came

How to avoid multiple tables tables to relations M: M?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 13:25:29
问题 How to avoid multiple tables tables to relations M: M? see the next model As can be seen by each multiple choice I create a couple of tables, that I have always worked well, but now I have lots of situations where this is going to happen. there is a solution without having to create that number of tables? Note :Obviously we must bear in mind that the solution does not complicate future queries, select, sort and query multiple tables that mix when reporting 回答1: If your priority is avoiding