Questions tagged [composite-primary-key]

Composite primary key is a primary key, which consists of more than one column. The column combination guarantees the uniqueness of the PK.

A Composite Primary Key is a Composite Key, which is assigned as Primary.

Primary key is a single field or the least combination of fields that uniquely identifies each record in table. When the primary key consists of more than one field, when we are talking about composite primary key. Composite or not, is the most appropriate key to be main key of reference for the table.

The primary key must not be null and must contain only unique values.

Primary keys are mandatory for every table. When choosing a primary key from the pool of candidate keys, always choose a single simple key over a composite key.

Links

984 questions
-1
votes
1 answer

UserRoles table with no PK

I have the following tables (among others): Users Departments Roles UserRoles The UserRoles table has the following fields: UserId RoleId DepartmentId (NULL) The idea here is I can give a user a specific role, for specific department(s), if the…
Him
  • 373
  • 1
  • 2
  • 15
-1
votes
1 answer

mysql FOREIGN KEY CONSTRAINT failing when recreating

I had already created the database and all tables with foreign key constraints, but I had a column in parent table which was unique and was part of composite key, so I had to drop all foreign key constraints from all child tables and then dropped…
ateebahmed
  • 183
  • 5
  • 19
-1
votes
1 answer

Creating view in Oracle database having four tables, each table has primary key

I have created four tables (company1, company2, company3, company4) with column names the same in all tables: empid, org, firstname, lastname. All four tables have the primary key as empid. I want to create a view which should bring all data from…
Kiran K
  • 13
  • 4
-1
votes
1 answer

MySQL : Composite primary key as foreign key

I try to do this into mysql : Create a first table with A, B, C columns and a composite primary key on A and B. Create a second table A, B, D, E columns with A, B, D as primary key and of course A, B referenced as a foreign from first table. I use…
-1
votes
2 answers

Updating a table with a composite key not working correctly

I have the following table: As you can see, date and bed form a composite primary key. I am trying to run this query: INSERT INTO days (date, operating_time, bed) VALUES ('2016-11-07', 6.55, 1) ON duplicate key update…
-1
votes
2 answers

TSQL : Check inserting data into the table

Let's say I have this table : CREATE TABLE [dbo].[finaleTable]( [VENDId] [bigint] NOT NULL, [companyName] [nvarchar](4) NULL, ----Others field CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ([VENDId]) ) ON [PRIMARY] GO And this…
stoner
  • 417
  • 2
  • 12
  • 22
-1
votes
1 answer

oracle identifier too long

New to oracle Im trying to assign composite key CREATE TABLE rep_contracts ( Store_id NUMBER(8), Name NUMBER(5) Quarter CHAR(3), Rep_id NUMBER(5), CONSTRAINT rep_contracts_rep_idstore_id_pk PRIMARY KEY (rep_id, store_id), CONSTRAINT…
-1
votes
1 answer

How to delete a composite primary key from mysql php using delete sql statement

I have been trying to delete a record from a table using delete sql statement but I found it difficult. Can you please look at my code and see what might be wrong?
-1
votes
1 answer

Composite Keys Rails Postgres

Going straight to the problem, I'm facing some problems with Active Record(NO RAILS) using composite keys. I'm using "gem composite_primary_keys" by the way. This table is a join table with two more fields. The problem is, when I do a simple query:…
-1
votes
1 answer

how to create composite primary key with indodb type database engine in mysql

I ' m creating composite primary key for my web site but it occurs some error code 1064... I tried but ...i did not Rectify that error ....so i m posting my question here... please suggest what changes should i do .....my tables are below DROP TABLE…
-1
votes
2 answers

smalldatetime vs int for Primary Key in SQL Server 2005 - 'Holidays' table

I have to create a new table "holidays" into a a SQL Server 2005 DB. first option: ID Int **PK** CustomerId nvarchar (10) HolidayDate Smalldatetime Description nvarchar (50) second option: CustomerId nvarchar (10) **PK** HolidayDate Smalldatetime…
lamarmora
  • 1,116
  • 4
  • 16
  • 32
-1
votes
1 answer

TSQL Primary key over too many columns?

I have table A and B which cannot be edited and both using composite primary keys (region_id, number). I have N tables, so called Information, each has its own ID as primary key. A(or B) <-> Info Tables are M:N relationship and I need such a…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
-1
votes
1 answer

Composite Primary key in JPA EclipseLink DynamicPersistence

Eclipselink Dynamic Persistence allow multiple primary key by : DynamicTypeBuilder.setPrimaryKeyFields(String primarykeysField...) But how can i find entity object(instance) by EntityManager.find( Entity Class , Object primaryKey) method to find…
Gaurav Kumar
  • 323
  • 2
  • 4
  • 10
-1
votes
2 answers

Re Increment the Primary Column after deletion of the record in table in Sql?

i want to do this one to my child table. check the primary key.It does not contains Identity Specification. when inserting data my table should be like this when i delete a record it should be shown below. how can i do this after deleting the…
Anjali
  • 1,680
  • 4
  • 26
  • 48
-2
votes
1 answer

What is the maximum column varchar size for Composite columns in Oracle

I am trying something like below and getting exception. CREATE TABLE test1( col1 varchar(4000) NOT NULL, col2 varchar(4000) NOT NULL, col3 varchar(4000), col4 varchar(4000), col5 varchar(4000) NOT NULL, col6 varchar(4000), col7 varchar(4000) ,…
anurag1007
  • 107
  • 1
  • 10
1 2 3
65
66