Protege 5 - Specifying primary key and foregin key - foreign-keys

Protege 5 - Specifying primary key and foregin key
Can you help me to place a primary key and foreign key for the following scene.
Thing
Person
Staff
Student
Course
Maths
CS
Staff has :StaffID, Name
Student: StudentID, Name
Object Properties : Studies, Teaches
FOllowing issues should be solved for me
1- I need to make StaffID, StudentID as primary Keys
2- I also wanted to make these as foreignkey relationship ( i dont know
whether its correct to say that)
3- Once primary key is defined, when i add individuals with same StaffID or
StudentID, how and where to check ? i mean to show there is a duplicated
data is added.
Please help me

Related

Data modelling in dynamo db for Ticket Management System

I am working in Dynamo DB for the first time . My assignment is Ticket Management System where it has 3 entities Department , User and Ticket. The relationship between each entity is.
I have identified the following access patterns
Fetch a Department.
Fetch all users in Department
Fetch a given user in Department
Fetch all Tickets belongs to the Department
Fetch all Tickets assigned to the User
for which i defined the following data model . I am thinking of creating GSI with Tickets as PK and User as SK to do 4 & 5
On a higher level I need to perform 2 updates . I can update the User to which the ticket is assigned and I can update the ticket status as inprogress, resolved . And in the table I have Ticket details as JSON object as below.
I need help from from the experienced people whether my understanding and approach is efficient.
I think you're on the right track. I'd design it as a table with two Global Secondary indexes. The base table looks like this:
The first Global Secondary Index like this (GSI1):
The second Global Secondary Index like this (GSI2):
Now for the why:
This design allows you to easily update the following things:
A user's department
A ticket's status if you know the ticket Id
A ticket's user if you know the ticket Id
A ticket's department if you know the ticket Id
You can get a bunch of information from this model:
Fetch a Department.
Query the base table with the department name or list all departments
Fetch all users in Department
Query GSI 1 with the Department Name and filter the sort Key using begins_with = USER#
Fetch a given user in Department
Sound like you know the UserId, so do a GetItem on the base table. If that's not the case, do the query mentioned in "Fetch all users in Department".
Fetch all Tickets belongs to the Department
Query GSI 1 with the department name as the PK and filter the SK using begins_with = Ticket#
Fetch all Tickets assigned to the User
Query GSI 2 with the user id as the PK and filter the SK using begins_with = Ticket#

Dynamodb schema design (map relational data to nosql)

Trying to get my head around this example from AWS to map a relational model to nosql
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html
A key concept highlighted there is:
Important
.... Most well-designed applications require only one
table. ...
Given that, the example table is as follows
It explains,
You define the following entities, which support the relational order
entry schema:
HR-Employee - PK: EmployeeID, SK: Employee Name
HR-Region - PK: RegionID, SK: Region Name
...
However, the entity HR-Employee - PK: EmployeeID, SK: Employee Name in the example table has SK values which are not Employee Names.
Also, it suggests the following query
but GSI-1 doesn't have PK of Employee Name.
I understand this could be a discrepancy in AWS documentation and I should raise it with them (which I have and they are notoriously bad in following up) but what I'm not sure is if the documentation is correct and my understanding is wrong (I'm inclined to believe the latter as AWS documentation is generally accurate).
Can someone guide me in the right direction in terms of a nosql schema mapping ? A correct example (with sample records of the dynamo table) for the schema in the above link would be much valued.
So I'll try and make this clearer for you, let me know if something still doesn't make sense.
To start, you mention the fact that:
However, the entity HR-Employee - PK: EmployeeID, SK: Employee Name in the example table has SK values which are not Employee Names.
The reason there are SK values that are not "Employee Names" is because the SK isn't only for "Employee Names", it is also used by other queries (such as Region Name, Country Name, etc.). Think of the SK as exactly what it stands for, a sort key. The documentation seems to miss the explanation of the extra SK they have, so let me summarize what you're looking at.
You have HR-Employee1, with Employee Name = Employee1, QuotaID (guessing what this key is) = QUOTA-2017-Q1, Some Other Key = HR-CONFIDENTIAL
These key names are not actually defined in the table, they all go under the sort key, and are only implicitly "employee name" or "quota id" or "region name".
What this allows you to do is query the employees data, using employeeID as PK and employee name as SK, but it also lets you query the employee Quota data (or whatever it is) by using employeeID as PK and quotaID as SK.
The same applies to your second question, concerning GSI-1. In essence, the way they have designed the table in this scenario is you have an SK "SortKey" where you can have various types of values to sort on, if that makes sense.

how to use foreign-keys with hsql create table?

could someone explain me how to use foreign keys in hsql?
I would like it in an create table, but working alter table is also ok.
I am working without tools, just in eclipse
whats wrong with the hsql code?
CREATE TABLE user(
t_id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
name VARCHAR(30),
lastname VARCHAR(30),
email VARCHAR(30),
--FOREIGN KEY (b_id) REFERENCES bookingnumber(b_id)
);
CREATE TABLE bookingnumber (
b_id INTEGER PRIMARY KEY
);
ALTER TABLE user
ADD FOREIGN KEY (fk_b_id) REFERENCES bookingnumber(b_id);
Perhaps you are trying to link each booking number to a user. In this case, multiple booking numbers may exist for each user. If you want to do this, add a column T_ID to the BOOKINGNUMBER table and created the foreign key on this table.
But your statement is linking each user to a booking number and doesn't have the correct syntax. It needs a column named B_ID in the USER table to work. And the syntax would be like this:
ALTER TABLE user ADD FOREIGN KEY (b_id) REFERENCES bookingnumber(b_id);
I was facing a similar situation and this helped me
CREATE TABLE child(c1 INTEGER, c2 VARCHAR, FOREIGN KEY (c1, c2) REFERENCES parent(p1, p2));
A more detailed explanation can be found at http://www.d.umn.edu/~tcolburn/cs4531/hsqldb_docs/guide/guide.html#N102F8

Foreign Key Input error in Link table (Error 1005)

I was trying to input my foreign keys into my Link table all at once.
I created all my other tables first then my link table, i added columns to my link table for the foreign keys (that worked). Then i went to insert my foreign keys and it doesn't work (by the way none of my other tables have foreign keys)
it says
#1005 - Can't create table 'waget.#sql-798_842' (errno: 150) (Details...)
i clicked on details and it comes up with INNODB
[ Variables | Buffer Pool | InnoDB Status ]
i click on variables it has a question mark next to 3 things Autoextend increment,Buffer pool size,Data home directory
im so lost i just want to be able to create foreign keys please Help
My foreign key insert code
use Dbase;
alter table Link
add foreign key (C_id) References C (C_id),
add foreign key (D_id) References D (D_id),
add foreign Key (T_id) References T (T_id),
add foreign Key (B_id) References B (B_id),
add foreign Key (H_id) References H (H_id);
Make sure both collumns are exactly the same: both int or varchar etc., both the same length, both null or not.

Django teacher students easy solution. Use separate tables, or permissions and groups? How? Other ideas?

How would you cope with following problem?
There are teachers, and students. Student can not view pages dedicated to teachers, and teachers can view pages dedicated to students. Teachers can have list of just students they teach. I want both teachers and students to use build in User to let them login.
I have following ideas:
Separate table for teacher and student with foreign key to build in user? - but the question is, can I easily render pages and distinguish who is teacher and who is student.
Permissions? Groups? and just one table Users? But to be honest I did not find the way how could I manage to achieve that what I mentioned at the beginning.
Would be grateful for any ideas, suggestions and comments, as I am thinking of it for HOURS!
As a rough start:
User Table
user id (primary key)
details (name, address, phone --i.e. common to a user of the system whether student or teacher.)
Student Table
user id (foreign key relationship to user table)
any student specific details (enrolment date, homeroom, etc.)
Teacher Table
a user id (foreign key relationship to user table)
teacher specific stuff (seniority, salary, etc.)
Classes Table
a class id (primary key).
details of the class
Grades Table
a user id (foreign)
a class id (foreign) -> these two keys used for doing a grade query.
a grade
(if a student can take a class multiple times, and have multiple grades, the grades table will need to have its own key, possibly with sequence type to establish the order in which they received them).
Your page that is displaying the user can query the user table display that information, followed by their student or teacher specific information. If its possible for a student to be a teacher, then you're able to do that too.