relational-database

Which highest normal form is this table in?

瘦欲@ 提交于 2019-12-02 01:01:35
Ticket Vname Nname 1 Oli Seitz 1 Andi Hofmann 2 Oli Seitz 2 Oli Schmidt 2 Tim Schmidt 3 Tim Hofmann This table represents a mapping of persons ( Vname, Nname ) and tickets ( Ticket ). Vname and Nname together identify a person, but every Person ( Vname, Nname ) can have multiple tickets ( Ticket ), and a ticket can be assigned to multiple people. The PK in this table are all three columns together. So this table should be 1NF because there is no multi dimensional data in one column. But then I struggle. I think it is 2NF and 3NF because I can´t find any functional dependencies. (Hope they are

Decoupling MySQL data versus ease of use

假如想象 提交于 2019-12-02 00:14:33
Assume a simple database for hotel reservations with three tables. Table 1: Reservations This table contains a check-in and check-out date as well as a reference to one or more rooms and a coupon if applicable. Table 2: Rooms This table holds the data of all the hotel rooms with prices per night and number of beds. Table 3: Coupons This table holds the data of all the coupons. Option #1: If you want to get an overview of the reservations for a particular month with the total cost of each reservation, you'd have to fetch the reservations, the rooms for each reservation, and the coupon (if one

SQLite delete with table alias [duplicate]

允我心安 提交于 2019-12-01 23:47:41
This question already has an answer here: Sqlite delete query error 3 answers I am trying to alias a table in SQLite, for example by the following command: (it is from the book i am reading"Database Management Systems by Ramakrishnan") DELETE FROM Students S WHERE S.sid=12546 This code gives a syntax error. Without aliasing, the following code works: DELETE FROM Students WHERE sid=12546 But, if i want to alias the table, what should i do? Can anyone help? Thanks The DELETE statement operates on a single table and does not use a table alias. so you will have to use your query as : DELETE FROM

Self-contained database?

梦想与她 提交于 2019-12-01 22:37:48
Is there a way to distribute a (smallish) self-contained relational database along with an Windows application that does not require users to install additional dependencies such as MS Access, SQL Server, MySQL, SQLite, etc.? Only the application will be accessing the database - not users directly. Microsoft SQL Server Compact 4.0 SQL Server Compact Edition 3.5 SQLite to name just a few. SQL Server Compact Edition 4 I would embed SQLite in my application. There's various ways to do this depending on the language your are using. 来源: https://stackoverflow.com/questions/4789908/self-contained

Keep table downtime to a minimum by renaming old table, then filling a new version?

谁说胖子不能爱 提交于 2019-12-01 21:44:06
问题 I have a handful or so of permanent tables that need to be re-built on a nightly basis. In order to keep these tables "live" for as long as possible, and also to offer the possibility of having a backup of just the previous day's data, another developer vaguely suggested taking a route similar to this when the nightly build happens: create a permanent table (a build version; e.g., tbl_build_Client) re-name the live table (tbl_Client gets re-named to tbl_Client_old) rename the build version to

psycopg2 mapping Python : “list of dicts” to Postgres : “array of composite type” for an INSERT statement

我怕爱的太早我们不能终老 提交于 2019-12-01 20:18:01
问题 Postgres version : 9.1.x. Say I have the following Schema: DROP TABLE IF EXISTS posts CASCADE; DROP TYPE IF EXISTS quotes CASCADE; CREATE TYPE quotes AS ( text CHARACTER VARYING, is_direct CHARACTER VARYING ); CREATE TABLE posts ( body CHARACTER VARYING, q quotes[] ); And I wish to perform the following insert, shown in SQL, but from Python Psycopg2. insert into posts(body,q) VALUES('ninjas rock',ARRAY[ ROW('I AGREE',True)::quotes, ROW('I DISAGREE',FALSE)::quotes ]); What is the syntax to

psycopg2 mapping Python : “list of dicts” to Postgres : “array of composite type” for an INSERT statement

烂漫一生 提交于 2019-12-01 20:03:55
Postgres version : 9.1.x. Say I have the following Schema: DROP TABLE IF EXISTS posts CASCADE; DROP TYPE IF EXISTS quotes CASCADE; CREATE TYPE quotes AS ( text CHARACTER VARYING, is_direct CHARACTER VARYING ); CREATE TABLE posts ( body CHARACTER VARYING, q quotes[] ); And I wish to perform the following insert, shown in SQL, but from Python Psycopg2. insert into posts(body,q) VALUES('ninjas rock',ARRAY[ ROW('I AGREE',True)::quotes, ROW('I DISAGREE',FALSE)::quotes ]); What is the syntax to achieve this (without loops and such). I am sure it is possible since the documentation says "Changed in

Should I make a foreign key that can be null or make a new table?

本秂侑毒 提交于 2019-12-01 19:30:48
I have a small question concerning with how I should design my database. I have a table dogs for an animal shelter and I have a table owners. In the table dogs all dogs that are and once were in the shelter are being put. Now I want to make a relation between the table dogs and the table owners. The problem is, in this example not all dogs have an owner, and since an owner can have more than one dog, a possible foreign key should be put in the table dogs (a dog can't have more than one owner, at least not in the administration of the shelter). But if I do that, some dogs (the ones in the

how to save marital relationship in a database

随声附和 提交于 2019-12-01 18:11:27
I have to save this information in a database Person -> is married to -> Person Where should I save that information? What is the proper design pattern should I apply here? Thank you! If you can only be maried to one person: 1:1 ------------- - Person - ------------- id (key) maried_to_id (foreign key) If you can be maried to more than one person or want to keep track of previous mariages, n:n ------------- - Person - ------------- person_id (key) ------------- - Mariage - ------------- first_person_id (foreign key) second_person_id (foreign key) start_date end_date (also first_person_id +

how to save marital relationship in a database

限于喜欢 提交于 2019-12-01 16:52:31
问题 I have to save this information in a database Person -> is married to -> Person Where should I save that information? What is the proper design pattern should I apply here? Thank you! 回答1: If you can only be maried to one person: 1:1 ------------- - Person - ------------- id (key) maried_to_id (foreign key) If you can be maried to more than one person or want to keep track of previous mariages, n:n ------------- - Person - ------------- person_id (key) ------------- - Mariage - -------------