Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

1 votes
0 answers
43 views
What "concept" means in the definition of an entity
One definition of "entity" in the Wikipedia page for [entity-relationship model][1] as follows: > An entity is a thing that exists either physically or logically. An entity may be a physical object such as a house or a car (they exist physically), an event such as a house sale or a car service, or a...
One definition of "entity" in the Wikipedia page for entity-relationship model as follows: > An entity is a thing that exists either physically or logically. An entity may be a physical object such as a house or a car (they exist physically), an event such as a house sale or a car service, or a concept such as a customer transaction or order (they exist logically — as a concept). I don't really understand what concept means in this definition and why a transaction or order is listed as a concept. A customer transaction or an order exists on paper (as bills) so can I say they exist physically? Besides, the event is also not a physical object so it should be a concept?
Kt Student (115 rep)
Feb 28, 2025, 05:46 AM
0 votes
0 answers
30 views
ER diagram Verification
An airplane company needs a database. Its desired design is described below. - For every airplane owned by the company the system needs to store its registration number, which is unique for every airplane. - Each airplane is associated with exactly one type. - A type is identified by its name. In ad...
An airplane company needs a database. Its desired design is described below. - For every airplane owned by the company the system needs to store its registration number, which is unique for every airplane. - Each airplane is associated with exactly one type. - A type is identified by its name. In addition, for every type we store its size. - Every airplane is based at a specific airport which should be stored in the system. - For each airport we want to store its ID and its capacity. In addition we want to store the neighbouring airports to it (an airport can neighbour more than one airport). below is my design do you think so its valid? enter image description here
Niraj Jain (1 rep)
Apr 27, 2024, 11:48 AM • Last activity: Apr 27, 2024, 11:55 AM
0 votes
0 answers
27 views
In an ER diagram, can an entity know information about a non-directly connected entity?
Imagine a simple database like this: ``` [credit card] --- has --- [customer] --- places --- [order] ``` Of course the order would know which customer placed it, but would it know which credit card the customer used to place it? Would the credit card and order entity sets need a direct relationship...
Imagine a simple database like this:
[credit card] --- has --- [customer] --- places --- [order]
Of course the order would know which customer placed it, but would it know which credit card the customer used to place it? Would the credit card and order entity sets need a direct relationship for this to be knowable? Another variation on this question:
[customer] ---places--- [order] ---funded_by--- [credit card]
Now obviously the order knows which credit card was used, but is there now no link between a customer and a credit card? (i.e. no way to get a list of all the credit cards owned by a given customer?)
Ethan Gascoigne (1 rep)
Mar 2, 2024, 04:35 PM • Last activity: Mar 5, 2024, 11:16 AM
0 votes
1 answers
1375 views
Using array VS separate table JOIN for many to many relationship
I have a use case where I need to create entity in ```postgresql``` to store some configurations. Example of two rows for configuration is below: |ConfigurationCode | OperationOne| OperationOneValue| OperationTwo| OperationTwoValue| |------------------|-------------|------------------|-------------|...
I have a use case where I need to create entity in
to store some configurations. Example of two rows for configuration is below: |ConfigurationCode | OperationOne| OperationOneValue| OperationTwo| OperationTwoValue| |------------------|-------------|------------------|-------------|-------------------| |ConfigurationCode1| INCLUDE | {'1,2,3,4,5'}| EXCLUDE| {'Name1, Name2, Name3'}| |ConfigurationCode2| ALL| {}| INCLUDE| {'Name1, Name2, Name3'}| Here, if I want to fetch configuration where
is 1 and
is Name4 I should get ConfigurationCode1 since it "includes" 1 and doesn't "exclude" Name4. I hope you got the use case. What the correct way of creating entity for such requirement? Using Arrays or Using Separate Table. I have used arrays to store
and
and use below query:
SELECT * FROM my_table_name
WHERE
(OperationOne = 'ALL' OR (OperationOne = 'INCLUDE' AND 'value' = AND(OperationOneValue)) OR (OperationOne = 'EXCLUDE' AND NOT 'value' = ANY(OperationOneValue)))
AND
(OperationTwo = 'ALL' OR (OperationTwo = 'INCLUDE' AND 'value' = AND(OperationTwoValue)) OR (OperationTwo = 'EXCLUDE' AND NOT 'value' = ANY(OperationTwoValue)))
The data in each array column can go upto 10k. And number of rows in table can upto 1k. What are advantages and dis-advantages of both approach?
postgis-user (1 rep)
Jan 5, 2024, 05:44 PM • Last activity: Jan 5, 2024, 07:42 PM
1 votes
1 answers
76 views
Confusion regarding Weak and Strong Entity types!
Apologies if this is a trivial question, I recently started studying about E.R. Model. Let me try to clarify my doubt using an example. Consider the two entities,Customer and Loan in a relationship such that; Customer (Strong Entity): • Attributes: CustomerID (Primary Key), Name, Address, etc. Loan:...
Apologies if this is a trivial question, I recently started studying about E.R. Model. Let me try to clarify my doubt using an example. Consider the two entities,Customer and Loan in a relationship such that; Customer (Strong Entity): • Attributes: CustomerID (Primary Key), Name, Address, etc. Loan: • Attributes: LoanNumber , Amount, Interest Rate, etc. Question 1 : If ‘Loan’ is to be a weak entity here does it necessarily imply that two customers may have same ‘Loan Number’? Otherwise ‘LoanNumber’ can identify the relation. ———————————————————————- Alternatively consider the following entities in a relation ; Customer (Strong Entity): • Attributes: CustomerID (Primary Key), Name, Address, etc. Branch (Strong Entity): • Attributes: BranchID (Primary Key), Location, Manager, etc. Loan : • Attributes: LoanNumber, Amount, Interest Rate, etc. Question 2: If ‘Loan’ is to be a weak entity here does it imply that, Customers in two branches or more branches may have the same loan number?
Quorthon (11 rep)
Dec 11, 2023, 01:14 PM • Last activity: Dec 11, 2023, 07:21 PM
0 votes
0 answers
206 views
Mariadb Triggers after multiple insert, update one table one one time
``` CREATE TRIGGER after_composers_insert AFTER INSERT ON composers FOR EACH ROW UPDATE listings SET composer_name = NEW.composer_name WHERE composer_id = NEW.composer_id; CREATE TRIGGER after_albums_insert AFTER INSERT ON albums FOR EACH ROW UPDATE listings SET album_name = NEW.album_name WHERE alb...
CREATE TRIGGER after_composers_insert AFTER INSERT ON composers
FOR EACH ROW UPDATE listings SET composer_name = NEW.composer_name
WHERE composer_id = NEW.composer_id;

CREATE TRIGGER after_albums_insert AFTER INSERT ON albums FOR EACH ROW UPDATE listings SET album_name = NEW.album_name WHERE album_id = NEW.album_id;

CREATE TRIGGER after_pieces_insert AFTER INSERT ON pieces FOR EACH ROW UPDATE listings SET piece_name = NEW.piece_name WHERE piece_id = NEW.piece_id;
Hello I'm trying to optimize all three triggers, in a single pass. Thanks for your help.
Alain Lagune (1 rep)
Nov 27, 2023, 12:29 AM • Last activity: Nov 27, 2023, 12:32 AM
0 votes
1 answers
62 views
How can I transform an exclusive constraint relationship from ER to RM model?
Let say we have two entities `TEACHER` and `COURSE`. There are two relationships between them. A `TEACHER` can teaches a `COURSE`, and also can learn a `COURSE`, however, the `TEACHER` cannot teach and learn a `COURSE` at the same time. Is it possible to ilustrate this constraint in the relational m...
Let say we have two entities TEACHER and COURSE. There are two relationships between them. A TEACHER can teaches a COURSE, and also can learn a COURSE, however, the TEACHER cannot teach and learn a COURSE at the same time. Is it possible to ilustrate this constraint in the relational model? How? Thank you!
xerez (1 rep)
Nov 18, 2022, 03:34 PM • Last activity: Nov 19, 2022, 01:34 AM
0 votes
0 answers
162 views
Is it good to join on different tables depending on discrimination column?
I want to build a MySQL database with different trading card, all belonging to different games. Each card, depending on the game, has several properties. For example : - A _Magic: The Gathering_ card has a `power` and a `toughness` (a nullable integer) - A _Pokemon_ card has a `retreat_cost` (a null...
I want to build a MySQL database with different trading card, all belonging to different games. Each card, depending on the game, has several properties. For example : - A _Magic: The Gathering_ card has a power and a toughness (a nullable integer) - A _Pokemon_ card has a retreat_cost (a nullable positive integer) And so on and so forth (not all of those properties are scalar, they could be basically any type). My first thought was this fiddle : https://www.db-fiddle.com/f/ew1cYbBABSCKrFMjD9qkJi/2 Of course, it basically works. I can find cards with their own properties, and I guess >I could map them to objects in my project using cards.id_game as a discriminator column, but I also see the following problem and wonder if I can do better : - I can't use any foreign key on cards.id_metadata because it could be an ID of any metadata table. Does anyone have another way to build this that could be "better" ? Appendix : The fiddle SQL in case the link dies :
create table cards (
  id int primary key auto_increment,
  id_game int not null,
  id_metadata int not null
);

create table games (
  id int primary key auto_increment,
  name varchar(180) not null
);

create table mtg_metadata (
  id int primary key auto_increment,
  name varchar(180) not null,
  power int default null,
  toughness int default null
);

create table pokemon_metadata (
  id int primary key auto_increment,
  name varchar(180) not null,
  hp int default null,
  retreat_cost int default null
);

alter table cards
    add constraint cards_fk_game
        foreign key (id_game) references games (id);
        
insert into games (name) values ('Pokemon');
insert into games (name) values ('Magic: The Gathering');

insert into mtg_metadata(name, power, toughness) values ('Grizzly Bears', 2, 2);
insert into pokemon_metadata(name, hp, retreat_cost) values ('Pikachu', 60, 1);

insert into cards(id_game, id_metadata) values (2, 1);
insert into cards(id_game, id_metadata) values (1, 1);
Altherius (101 rep)
Sep 5, 2022, 05:50 PM • Last activity: Sep 5, 2022, 06:04 PM
Showing page 1 of 8 total questions