Varchar as Primary Key

2

Hello I made a database based on a project I found on the Internet to do a REST.   The problem I have is that the Primary Key is type varchar and I can not auto-increment it since Mysql will not let me. I have to do the manual insertion.

How can I manually auto-increment it? I was seeing that with the triggers it could be done but I had no luck.

The tables are these:

 Tabla T_Reserva

fechaLlegada: Date
numNoches: integer
numAdultos: integer
numMenDos: integer
numMenDosDoce: integer
localizador: String
observaciones: String
precio: Double
régimen: String
codCliente: String
codHotel: String
tipoHab: String
Clave primaria: localizador
Clave foránea hacia T_Cliente codCliente
Clave foránea hacia T_Hotel codHotel
Clave foránea hacia T_TipHab tipoHab, codHotel
Clave foránea hacia T_Tarifa fechaLlegada, regimen, tipoHab, codHotel 

Como clave primaria alternativa tenemos, codigoHotel, codigoCliente,
FechaLlegada, pero de esta manera sólo puede haber un reserva para un cliente en
una fecha determinada.

I should change the Primary Keys to integer . Because at best he put them as varchar for some reason.

Thank you.

Tabla T_Cliente

codCliente: String
nombre: String
apellido: String
dirección: String
provincia: String
país: String
código postal: String
teléfono: String
móvil: String
email: String
Clave primaria: codCliente 

Tabla T_TarCre

número: String
caducidad: String
tipo: String
codCliente: String
Clave primaria: número
Clave foránea hacia T_Cliente codCliente 

Tabla T_Hotel

codigoHotel: String
Nombre: String
fechaMaxEntrada: Date
numMaxNoches : integer
Clave primaria: codHotel 

Tabla T_TipHab

tipo: String
numMáxPersonas: integer
disponibilidad: integer
codHotel: String
precio: real
Clave primaria: tipo, codHotel
Clave foránea hacia T_Hotel codHotel
Tabla T_Tarifa
precioNoche: Double
fechaInicio: Date
fechaFin: Date
regimen: String
tarifa: Double
codHotel: String
tipoHab: String
Clave primaria: fechaInicio, regimen, tipoHab, codHotel,
Clave foránea hacia T_TipHab tipoHab, codHotel 
    
asked by TOMAS 29.01.2018 в 17:30
source

1 answer

1

If you are following a guide, it is good that you evaluate the code to know in which way the self-increment in the database will be handled, either on the code side or the database, you should also know that not all the primary keys are numbers is also very accepted that they are randomly generated alphanumeric codes such as the universally unique identifier (UUID) something that every programming language and database offers you a generator among its libraries.

    
answered by 29.01.2018 в 17:54