I have read here that it is probably better to use an AI integer to denote users as opposed to an assigned domain (string) username. I can accept that, however, when I am including in the 'users' table the auto generated userid and the unique domain usernames, how should I denote that in other tables as FKs? eg. Department table with 'userid' AND 'domainname' or just userid; hardware table with 'userid' AND 'domainname' or just 'userid' as owner?
Primary Key as domain username AND userID?
1k Views Asked by ksdst1 At
2
There are 2 best solutions below
0
ruakh
On
Just the user-ID. This is a key component of database normalization; if the other tables contain any other information that can be completely determined by the user, then you introduce the risk of inconsistencies whereby different records make different claims about a given user.
Related Questions in SQL
- SQL schema for a fill-in-the-blank exercise
- Hibernate: JOIN inheritance question - why the need for two left joins
- What's supposed to be the problem in this query?
- Compare fields in two tables
- How to change woocomerce or full wordpress currency with value from USD to AUD
- Dynamic query creation with Array like implementation
- SQL query to get student enrolled in this month in a course - Moodle
- SQL LAG() function returning 0 for every row despite available previous rows
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Use row values from another table to select them as columns and establish relations between them (pivot table)
- SQL: Generate combination table based on source and destination column from same table
- how to use system's environnement variables in sql script
- PHP fetchAll on JOIN
- Multitable joining in Sql
- How to display name starting from 'z' by using BETWEEN cmd only?
Related Questions in PRIMARY-KEY-DESIGN
- Is it wise to construct a custom string (combination of entity, year and alphanumeric) to have as a primary key for a postgres database in Django?
- Selecting the right keys for a DDB table
- Are Primary Keys Recommended on a Timescale Hypertable?
- ETL process where Primary Unique key changes after order status change
- How to create a Custom Unique Primary Key using prisma?
- SQL Server use same Guid as primary key in 2 tables
- In SQL is it possible to create a serial primary key that begins with a specific letter and is followed by a specific amount of numbers?
- JSON object with id as primary key schema design
- Extension of an ID based off the ID of another table
- SQL Server Removing Duplicate Rows & Managing Keys
- Create a Primary Key on a large table (6Million records) without locking the table in PostgreSQL
- Can a CLR UDT be a PK on a table?
- Why laravel delete() function getting error?
- REST API Primary Key Design MySQL
- Why two primary keys in a table is not allowed?
Related Questions in SQL-TYPES
- Postgres plsql return one column from table with dynamic type
- ORACLE : How to add a nested table to an existing type
- PLSQL aggregation function using type object PARALLEL_ENABLE AGGREGATE
- Postgresql Jsonb Java Hibernate 6 JdbcTypeCode
- Getting error when retrieving Spatial Data from my database
- MySQL alternative to PostgreSQL's custom data type (and domain)
- Avoid error out of range SQL during database migration
- Converting SQL type to PLSQL collection / converting one collection type to another
- using SqlGeography types in C# client-side
- SQL Server compatibility creates issue
- Assign ref variable value oracle
- Is There a Way to Convert System.Data.SqlTypes.SqlBinary of Datatable To Type System.Byte[]?
- DataTable not populating a datatype fully in sql server
- create a PySpark Schema for a tuple composed of a list and an array
- Insert data into user-defined type elements of a table in postgresql
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I'll give you some Idea but not exact answer. -"this answer is base on my understanding in your question"
Design example :
Table
Users:Your primary key here is
UserIdand you can use this as foreign key in other table.Table
Department:Your primary key here is
DepartmentIdand you can use this as foreign key in other table.You also have a foreign key called
UserIdfrom tableUsersTable
Hardware:Your primary key here is
HardwareIdYou also have 2 foreign keys called
DepartmentIdandUserIdOK, Each table must and required to have a own primary key and you can't use the
DepartmentIdandUserIdto become primary key in tableHardwarebecause they are foreign key in this table.DepartmentId- Include, so you will know the department where the hardware base.UserId- (Optional), You will know the owner or user of this hardware by using only theUserId