Most voted "primary-key" questions
A primary key corresponds to one or more fields within a table where values will be uniquely identified.
Learn more…44 questions
Sort by count of
-
15
votes3
answers22703
viewsWhen is the use of composite primary key recommended?
A key simple is associated with a single value, or field, of the record. A key composed corresponds to the combination of two or more keys, and may be required to eliminate ambiguity by forming a…
-
12
votes4
answers2869
viewsIs it recommended to use natural primary key?
Natural primary key is one that contains real data, not just a random value, but an integer. Example: // comum CREATE TABLE pessoas ( id INTEGER PRIMARY KEY, cpf INTEGER NOT NULL, // outros campos…
-
7
votes1
answer181
viewsIs the "Row ID" equal to the primary key?
The function Insert of Android returns a row ID according to the documentation, the Row ID of the Newly inserted Row, or -1 if an error occurred To row ID corresponds to the primary key, ID, if…
-
5
votes1
answer1718
viewsHow does auto increment work with composite keys in the Myisam engine?
I ended up taking a table to manipulate, I noticed that sometimes the value of auto increment repeated, the first thing that called me the attention was that the key Primary was composed of two…
-
5
votes3
answers6709
viewsIs it possible to have more than one Primary key in a table?
I have a gym and I’m wearing one Pk for all gym users to have their own (ID). It is possible to use other PK in the same table? For example: to prevent Número da Matricula or even the CPF/RG if…
-
5
votes1
answer67
viewsIs it possible not to allow duplicity in a combination of 2 columns or more?
I know that SQL Server has the Primary Keys and start not to allow duplicate records, but it is possible to do this through 2 columns or more? As an example, I have a table with column, house and…
-
4
votes1
answer523
viewsUsing hexadecimal as ID in the database
Through the navigation bar, we realize that Google uses hexadecimal values to identify records: The print above was taken from Gmail, but the same occurs for other services like Google Drive. What…
-
4
votes1
answer78
viewsSingle ring value
I’ve seen several posts on the subject but it’s not exactly what I was looking for. A while ago when I was in internship, I was told to keep some records with a unique id on each one, and they told…
-
4
votes3
answers1476
viewsIs it necessary to create a primary key with auto increment?
When I create a table that already has a field with an index unique, that will be referenced by other tables, can I leave it as primary key? Or is it good practice to create another field, with auto…
-
4
votes1
answer117
viewsIs it bad practice to use "Guid" and "int" for the same bank?
In a project I’m developing I prioritize the use of Guid for PK because of the ease for me, but it has a table that would be more advantageous to use int. This is wrong?…
-
3
votes1
answer32
viewshow to create a postgresql table? how do you use alter table and drop table? and what are the differences between Primary key and Foreign key?
People help me with postgresql studies.How do you create a postgresql table? how do you use the alter table and drop table? and what differences of key Primary and key Foreign ?
-
3
votes2
answers835
viewsHow to make an auto ID increment relative to another field in Postgresql "Postgresql"?
Personal it has been a long time since I look for a way to do this, what would be the correct way to make an auto increment that depends on another field as in the example below? id_empresa |…
-
2
votes1
answer203
viewsIndexes in primary key columns
I know that each case is a case, and that there are no ready-made rules on the creation of indexes. In my case, considering that the primary key of each table of my bank is used in wheres of my bank…
-
2
votes1
answer236
viewsIs using the oid column in Postgresql as the primary key correct?
Postgresql creates by default the Oids column (object identifiers), you can get it by doing. select oid, * from table Problem that I have a table that has no primary key, and I want to map it in…
-
2
votes2
answers662
viewsSet Auto Increment position, always for the smallest ID
I have a database Mysql, where contains a table called usuarios This table contains a column ID, where is Autoincrement and kind INT I need you to: Whenever I enter the first result the ID be equal…
-
2
votes0
answers179
viewsAuto ID increment relative to another field
I have been looking for something to solve such problem that I have been finding in other systems that I developed, I would like to know a solution for how to make an id auto increment, but an auto…
-
2
votes1
answer3849
viewsHow to delete primary key (PK) in Mysql?
I have the following table in Mysql: The id column is primary key. I would like to remove the primary key from this table. How can I do this? Thank you.…
-
2
votes1
answer65
viewsIs exposing the PRIMARY KEY of an entity considered a serious security problem?
Considering a very basic example: suppose there is a web system in which the user can view his profile (and other users) through a unique identifier passed to a route, for example:…
-
1
votes3
answers906
viewsCan a primary key be used on a foreign key?
The following example may occur? | Id | nome | data | qnt | PK -> Id FK -> (Id, qnt) Or is there some kind of restriction?
-
1
votes1
answer408
viewsInsert to foreign SQL keys
I am learning a programming language and I set out to develop a budget program. My first obstacle is to add the values of the primary keys in the foreign keys of the respective tables. This code…
-
1
votes0
answers286
viewsUnidac uniQuery component does not return keygenerator value
I’m having trouble inserting into Firebird using Devart’s uniQuery (Delphi 7 with Unidac) component. The primary key field is in the query fieds and the component configuration is like this:…
-
1
votes3
answers1439
viewsSaving ID from a table with two Primary Keys with Hibernate
Hello, I am having a problem while saving data in one last table. Well, this table has two Foreign Keys and the same are Primary Keys: When going to Controller, save the table, I use the following…
-
1
votes1
answer305
viewsseveral foreign SQL keys
I have the following table: items (ref) the attribute "ref" as the primary key of the table, may have associated several secondary keys in other tables [ex:Tabela1(ref) and table2(ref) being "ref"…
-
1
votes0
answers552
viewsHow to put an attribute as a foreign and primary key at the same time?
Utilise Mysql Workbench and I have to represent a DER in the physical model. I come across a specialization: TABELA_PESSOA cpf* nome sexo TABELA_CLIENTE cpf_pessoa* email senha TABELA_FUNCIONARIO…
-
1
votes2
answers133
viewsCakephp - 1~n ratio
Good evening, I’m having a hard time on Cakephp 3 and the problem is this:: Cannot Insert Row, some of the Primary key values are Missing. Got (, ), expecting (idstorie, users_iduser) The system…
-
1
votes1
answer1898
viewsDifference and use between Primary Key and Foreign Key
I did a database modeling relating some tables and at the end of everything I was told that I was wrong for not having PK and FK keys. The question is, how do I differentiate a Primary Key from a…
-
1
votes1
answer16
viewsRestarting indexes for each new client
I need help from you. I have a small system that allows the registration of companies, and each one can contain one or more members. See a summary of the tables: //Tabela Empresa emp_codigo (chave…
-
1
votes1
answer122
viewsCan I get more than one FK referencing the same PK?
I wonder if it is possible to reference foreign keys (FK) from different tables to the same primary key (PK). Below is a piece of the SQL command CREATE TABLE Run( Project_Code INT FOREIGN KEY…
-
1
votes1
answer243
viewsForeign key with 3 primary keys
Hi. I have this table with 3 primary keys and I need to reference it in another table. It’s like? I was just going to put an int-type id in the monthly table to be the only primary key. But each…
-
1
votes2
answers68
viewsForeign Key (foreign key) referencing utility in the database
I have a question in jobs with databases. Exemplifying, as the image below: Well, I know I should include in the table agendar_consulta the user who needs a consultation and the doctor who will…
-
0
votes1
answer309
viewsHow to create a sub-select in oracle in a composite key table?
The table has a composite primary key, and the fields are a date (ID_DEPURACAO) and a number(SEQ_DEPURACAO). What I want to do is a sub-select that takes only data greater than a given date and that…
-
0
votes0
answers749
viewsHow to find out in SQL which is the primary key of the table?
I am learning SQL, and ran into the following problem: I need to know which of the columns is the primary key of the table. Have some command I can use in SELECT to get as return that information?…
-
0
votes1
answer294
viewsID sequence advances +1 during error [Postgresql]
I have the following table in the database in postgresql The fact is that the column Description is unique_key so for testing issues I decided to insert some records with the repeated values in the…
-
0
votes3
answers43
viewsProhibit lines from being exactly the same in the database
I have a system that integrates data from three different banks, more specifically the registration of the companies of these three banks, I created a table where are stored the integrations that…
-
0
votes1
answer1565
viewsLaravel/Eloquent: How to create a primary key composed of two foreign keys?
I am creating a simple system for school management and I will have a table called 'class students', where the primary key should be composed by the student id and class id, which are foreign keys…
-
0
votes1
answer31
viewsWhy don’t you create Foreign Key?
I ran the commands in Mysql Workbench, but did not create the Foreign Key connection, which is wrong in querys? create table Computador ( ID int NOT NULL primary key AUTO_INCREMENT, Nome varchar(45)…
mysql database mysql-workbench foreign-key primary-keyasked 5 years, 5 months ago Felippe Jaqson Chemello 3 -
0
votes1
answer85
viewscreation of a composite KP
I have two tables: tbl1 and tbl2. In the tbl1 I own a pk and in the tbl2 I own a FK which refers to PK of tbl1 and a pk. With this, I can make a pk composed for the tbl2 with these 2 fields ? EX:…
-
0
votes1
answer107
viewsDoubt with foreign key
To register the matches of a football championship the following tables were defined: Time ( id int primary key, nome char(20), pontos int, nroVitorias, golsMarcados int, golsSofridos int ) Jogo (…
-
0
votes1
answer1335
viewsError Code: 1062. Duplicate entry '2' for key 'PRIMARY'
I am trying to update the local table with the data from the cursoProunine table with the following command : Insert into local (idlocal, Uf, city) SELECT idlocal, uf_search, city_search FROM…
-
0
votes0
answers17
viewsIn which cases is Primary Key NONCLUSTERED more advantageous?
Good afternoon, you guys! I was researching about Primary Key Clustered and found that answer: "The difference that actually exists is between the fields of the type NONCLUSTERED clustered clusters.…
-
0
votes2
answers122
viewsIs using the Mariadb JSON type a good one for saving primary keys?
I’m developing a database for a local travel agency: I need to pick up all the passengers and store them in one entity Viagem, so that in the "passengers" field of the latter would be of the JSON…
-
0
votes1
answer58
viewsInsert data in multiple related tables
I started a project at the same time that I started studies in a database. I created a customer phone only table and another table for all customer data, including phone as Foreign key. in the phone…
-
0
votes1
answer84
viewsMysql key creation error
I’m making the following mistake: Error Code: 1005. Can’t create table bravo.tb_gerenciador (Rrno: 150 "Foreign key Constraint is incorrectly Formed") follows the script: -- MySQL Script generated…
-
-1
votes1
answer213
viewsComposite primary key definition syntax in the H2 Database engine
I am trying to define a primary key composed of two columns when creating a table in the H2 Database Engine (http://www.h2database.com/html/main.html), but I couldn’t find the syntax in the manual.…