Avoid repeated data entry? [closed]

-1

I am creating a reservation system for medical appointments, but I do not know how to program that the user can not enter an appointment at a time that is already saved. I would greatly appreciate your help

    
asked by Celeste Guerra 10.12.2018 в 03:05
source

2 answers

1

You can ensure that your field is unique with the unique statement, so there will be no repeated data in the column of your table, greetings.

If you already have the table created you can use this:

ALTER TABLE nombreTabla ADD UNIQUE (columnName)

and if you're just going to create the table:

CREATE TABLE tableName (     field1 int NOT NULL UNIQUE,     campo2 varchar (255) NOT NULL,     field3 varchar (255),     int field4 );

    
answered by 10.12.2018 в 04:07
0

Try with IF on your SQL Server, something like:

IF NOT EXISTS (SELECT 1 FROM NOMBRE_TABLA WHERE COLUMNA_HORA_REGISTRO = @ValorHoraRegistrar)
    -- El Insert
ELSE
    -- El mensaje de que ya existe cita a esa hora
    
answered by 10.12.2018 в 20:18