Featured post
- Get link
- X
- Other Apps
Primary Key Violation explained with composite key
Hi friends,
We all know that there is an error which related to primary key of a table known as violation of primary key constraint.We can define primary key of a table with single column in the table.If you check below images it will be easy to understand.First i will explain primary key violation error with single column as primary of the table.
Create Table Employee with Id as Primary Key |
Insert values into Employee Table |
Select values from Employee Table |
Now let us try to insert a new row , Id with value 1 as shown below picture
Violation of Primary Key |
So as shown in above image,When try to insert Id with value 1,then we will get violation of primary key error.Because of already there is an entry with Id=1 in the employee table
Now let us check what will happen if Primary key of table is a group of columns ,that means there is more that one column in the primary key of the table.I will explain it with images
Create Employee Table with Composite Key |
Insert values into Employee Table |
Select Values from Employee Table |
Now let us try to enter a new row whose Id and Name having values which is already entered in the employee table.So we will get violation of primary key error in SQL Server Database
So i hope you understood how the primary key with single column or multiple column(Composite key) generates the violation of primary key error
Thanks
Popular Posts
How to Check React Version Installed in Your System by Checking PACKAGE.JSON File and Executing Command from COMMAND PROMPT
- Get link
- X
- Other Apps
Execution failed for task ':react-native-reanimated:externalNativeBuildDebug' solved
- Get link
- X
- Other Apps
Error: Invalid `prisma.$executeRaw()` invocation: fixed using log: ["query"] option
- Get link
- X
- Other Apps
app keeps stopping error solved in android studio emulator using logcat in react native project
- Get link
- X
- Other Apps
ERROR Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined
- Get link
- X
- Other Apps