relation between real person and legal person in master data service - sql-server

I want to create master data for an organization. I have 5 basic data, one of them is persons. I use the master data service (SQL server). I designed models with the named party and some entities. my entities are Person, organization and Source_relation and another domain base table. I have an attribute in the source_relation table that shows a code. each party has a code and it is in the source_relation table. The person and organization have FOREIGN KEY to source_relation entity. how to design this in master data service? using a unique identifier for the relation between these tables are correct?

Yeah, that will wise to use FOREIGN KEY to connect between two tables.

Related

Can we create foreign key without models in Django?

I am using SQL Server database and Django. I have a Database named as Person Database and Other database as Student Database. In Person database I created models, but in Student database there are no models because the tables and data are already existing. So I am getting data of Student database using Pyodbc. Now I am creating a new model in Person database where I need to create a foreign key for student database. Can anyone help me out how to do it.
You cannot create a Foreign Key relation in between tables of different databases. Foreign Key relations can only be created between tables of the same database. There is a workaround on this, although it is not recommended. Please refer this answer.

Service Oriented Architecture: Foreign Key Across Different Databases

We are implementing Services Oriented Architecture (SOA). We have different service databases for each, Customer Management, Orders, Shipping, Refunds. What is strategies to maintain foreign key relationships across tables in different databases (since cross database foreign keys are not allowed in SQL Server)? Should foreign keys be substituted with business API rules?
This is not Microservices; where database information is replicated in each arena, but SOA. We did not want put everything in 1 database, since different backup maintenance hours, did not want deadlock/runaway query to bring down all services. Service Oriented Architecture does not dictate if we should have 1 database or multiple.
You can use a Guid(UUID) as the key of your entities, generated by the creator and then you can use that Guid across databased and tables to reference the entity in question.
for example, when you create a new order, the ui will generate the order's Id, send a message to the component creating the order, the component will then publish an event using that orderId so that the other components can do related work to that order without accessing the database to get that id.
Make sense?

How do I store data that is shared between databases?

How do I store data that is shared between databases?
Suppose a database for a contact management system. Each user is given a separate database. User can store his/her contacts' education information.
Currently there's a table called School in every database where the name of every school in the country is stored. School table is referenced as a FK by Contact table.
School table gets updated every year or so, as new schools get added or existing schools change names.
As the school information is common across all user databases, moving it into a separate common database seems to be a better idea. but when it's moved to a separate database, you can not create a FK constraint between School and Contact.
What is the best practice for this kind of situation?
(p.s. I'm using SQL Server if that is relevant)
Things to consider
Database is a unit of backup/restore.
It may not be possible to restore two databases to the same point in time.
Foreign keys are not supported across databases.
Hence, I would suggest managing the School -- and any other common table -- in one reference DB and then replicating those tables to other DBs.
Just straight out of the box, foreign key constraints aren't going to help you. You could look into replicating the individual schools table.
Based on the fact that you won't query tables with the SchoolID column very often I'll asume that inserts/updates to these tables will be really rare... In this case you could create a constraint on the table in which you need the FKs that checks for the existence of such SchoolID in the Schools table.
Note that every insert/update to the table with the SchoolID column will literally perform a query to another DB so, distance between databases, the way they connect to each other and many other factors may impact the performance of the insert/update statements.
Still, if they're on the same server and you have your indexes and primary keys all set up, the query should be fairly fast.

Can you lazy load when model has associations, but the database does not?

I am working on an old database, that i do not want to touch or modify in any way if possible.
I want to build a new application that uses it's data but the database has no actual relations despite having primary and foreign keys linking tables.
If i import these tables into an Entity Framework model and add the associations manually, will i be able to use things such as lazy loading and linq?
Many thanks,
Kohan
This is definitely possible. Entity Framework simply generates SQL queries containing joins or where clauses that reference columns that you define in your conceptual model as foreign keys. The generated SQL is directly executed by the database.
Primary and foreign keys are only in your database for referential integrity. As a very simple test you can execute a SQL statement directly in your database that joins two related tables that do not have a foreign key relationship. You'll see that the query simply works. Entity Framework does exactly the same when you correctly define the relationships in your model.

Oracle same table name on different schema?

Is it possible to have same table name on different schema with different data on the tables within the one database? I think rather than create multiple database (that hold same table name) i should create multiple schema instead.
Something like:
Schema 1:
table A, table B
Schema 2:
table B, table X
PS: table B hold different data for each schema
And most basic question did every schema (user) hold different table set? In SQL Server and MySQL every user on same database have same table set, the difference was only on roles, how about Oracle?
Thanks
Yes this is possible. A schema in Oracle is what a MySQL user would call a database.
However, you need to be careful when accessing either of the tables now if the user you connect with to the database instance has access to both. To unambiguously reference a table in a specific schema, use schema.table.
Here's the documentation on namespaces: https://docs.oracle.com/en/database/oracle/oracle-database/20/sqlrf/Database-Object-Names-and-Qualifiers.html#GUID-3C59E44A-5140-4BCA-B9E1-3039C8050C49
As jackrabbit says objects in different schemas have different namespaces.
Each schema in the database has its own namespaces for the objects it contains. This means, for example, that two tables in different schemas are in different namespaces and can have the same name.
Within a schema things are a little more complex.
Because tables and views are in the same namespace, a table and a view in the same schema cannot have the same name. However, tables and indexes are in different namespaces. Therefore, a table and an index in the same schema can have the same name.

Resources