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
- Can MVC.NET prevent SQL-injection at razor or controller level?
- SQL server not returning all rows
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Creating a parametrized field name for a SELECT clause
- Combine two rows based on common ID
- Column displays each count
- Slick query for one to optional one (zero or one) relationship
- Aggregate and count in PostgreSQL
- MAX and GROUP BY - SQL
- SQL statement for a tricky 2 table query
- How to create nested selects with sql?
- Pull and push data from and into sql databases using Excel VBA without pasting the data in Excel sheets
- Best Practice for adding columns to a Table in Oracle database
- SQL FIFO STACK using two tables
- SQL Query - Order by String (which contains number and chars)
Related Questions in PRIMARY-KEY-DESIGN
- Allocate ranges of primary key integers
- Primary Key as domain username AND userID?
- MySQL - Using foreign key as primary key too
- Primary Key and Composite Key
- Are Primary Keys Recommended on a Timescale Hypertable?
- Why does an SQL table have multiple primary keys?
- SQL tables primary key
- Database design: Primary key from multiple data sources
- JSON object with id as primary key schema design
- ASP MVC code first create computed primary key
- 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?
- Output Inserted or deleted in SQL Server
- Use of natural key in date dimension
- MySQL moving primary key from varchar to int
- REST API Primary Key Design MySQL
Related Questions in SQL-TYPES
- What is a portable SQL data type for storing boolean values?
- Primary Key as domain username AND userID?
- Is it possible to define bit column in sqlite?
- Sql Spatial Type, Code First migration and Azure DB
- Varchar Encoding in MySQL
- MySQL alter table - changing a TINYINT to a SMALLINT
- Set decimal(16, 3) for a column in Code First Approach in EF4.3
- Automapper value type to SqlType conversions
- Invalid data type while using user defined table type
- Decimal(19,4) or Decimal(19.2) - which should I use?
- MySQL alternative to PostgreSQL's custom data type (and domain)
- What are SQL Server data-types mapped to by default in ADO.NET?
- datetime vs smalldatetime
- CREATE FUNCTION for <> T-SQL and CLR types for return value do not match
- using SqlGeography types in C# client-side
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 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