How to design this relaional database - database

I want to question about relational database. I have two tabel , They are airport_tbl and complain_tbl. Primary key of airport_tbl is airport_id and their fields are airport_name and airport_location. In complain_tbl I want to make airport_departure and airport_arrival and they are foreign key of airplane_tbl. Is is possible? Or dou you have other idea for designing this database? I will appreciate if you can help me. Thanks

Related

Estabilish Relationships in Snowflake

I have 10 tables created in Snowflake. How do i model them? I mean how do i establish relationship between the tables in the form of a parent-child relationship or in the form of Facts and Dimensions?
Can you please share a sample model if you have?
Snowflake supports defining and maintaining below constraints, however it does not enforce them, except for NOT NULL constraints, which are always enforced.
UNIQUE
PRIMARY KEY
FOREIGN KEY
NOT NULL
For constraints and related details please refer
https://docs.snowflake.com/en/sql-reference/constraints-overview.html
For sample code/model you can check at https://docs.snowflake.com/en/user-guide/table-considerations.html

sql importance of diagram relationships and keys

I have searched everywhere and although there is plenty of information I only get more confused each time.
So, with that said, I want to ask you how important are relationships. I'm talking about diagram relationships. I've been told that if the querys are well done it works just fine. So, my question remains... How important is it?
That and, refering to table relationships and their primary/foreign keys, for two tables to be able to have a relationship between a primary and a foreign key does one of them have to have only one key? For instance, I have these two tables, in the image bellow, that I want to make a relationship between id_utilizador from Utilizadores and id_utilizador from Apostas. But I get an error, while trying to make it (also in an image bellow). I you could help undestand why I'd very much appreciate it.

Normalization. Looking for feedback on what should be 3NF

I am creating a database for a super market in my database class. The database needs to be at least 3nf but if possible, BCNF. Could someone let me know if this is satisfactory? I believe it is and I just want to make sure.
The values all look atomic, the only problem I see is in your System.orders table. 3NF should not store calculated values.
Here's a good topic page on calculated values.
The other one I'm not sure about is the lack of a primary key on System.orderItems. I've been told it's good practice for each table to have a Primary Key. On your relational table, you make both orderId and itemId a linked Primary Key.
Here's a good discussion on the need for a Primary Key.
Hope that helps.

Database design query regarding column that can have multiple values

I have a table named Forum which has following columns:
stu_id -> foreign key
query
query_date
solution
query_title
Now i am confused on how to implement this table in mysql. All the columns in the table will have single value at a time except the solution column , as we know that for a single query there can be multiple solutions. So should i create a one more table say solution_table.
Now the Tables will be:
Forum
stu_id -> foreign key
query
query_date
solution_id
query_title
Solution_table
solution_id
solution_ans
IS this correct?Or is there any other method to implement this?
Yes, that would be the correct way to implement this. If the solution_ans are going to be a finite list of solutions then that is all that you would need in the Solution_table. If the answers are going to be dynamic, I would think about having a foreign key in the solution_table that links to the stu_id. This way when you are looking at the data you can easily connect each answer to the forum post/question
I would look into normalization of databases to understand why this is a good solution for this particular problem.

Tips for build foreign keys into a legacy database

I've got a database that doesn't have any foreign keys. I've done some checks and there are a a fair few orphaned records.
Its a pretty large database 500 + tables and I'm looking at the possibility of building the foreign keys back in.
Other than trawling though every single table over time?
Has anybody ever been through this process before and can maybe offer some insights or tips on how to make the process a little easier.
Any help advice appreciated.
I assume you mean "doesn't have any foreign key constraints"...if there were no foreign keys, you wouldn't know which records matched at all.
Do the primary and foreign key fields have the same name? As in, the PK table has a "CustomerId" field and the FK table(s) also have a "CustomerId" field? If so, you might be able to query the column properties (perhaps using INFORMATION_SCHEMA, you didn't mention an RDBMS) to figure out some implied relationships. Just query for all the tables that have a field called "CustomerId" that is not a PK and there's a good (but not certain) bet that those tables should have an FK constraint to the Customer table. You could even use the output of the query to generate the DDL to create the constraints.
You can work from the largest to smallest tables, or start with the least performant area of the database. Adding keys should help your performance significantly, but you'll have to resolve the orphan rows first. You may need input from the business for that. Expect them to be very confused about what's going on.

Resources