2 Unique Key With One Of Them Possible Duplicate
Hello I want to ask if it's possible to set 2 unique key and in some condition one of them can have duplicate but the other one is not.
The example is like this :
orderID trans_date 1 2016-02-25 01:00:00 1 2016-02-25 01:00:01 2 2016-02-25 01:00:00
As you can see if I only make
trans_date an unique key then it can be duplicate, it also the same as the
So instead of create unique id for one of them, why dont we create for both of them.
OrderID and trans_date can't be the same as the other later.
Is it possible ?
If you want two keys to be unique as a pair, then you can create a unique index:
create unique index unq_example_orderid_transdate on example(orderID, trans_date);
Or, you can create a unique constraint which does essentially the same thing.
- → I can't do a foreign key, constraint error
- → How to implement DbDongle::convertTimestamps as workaround of invalid timestamps with MySql strict
- → MySQL error "Foreign key constraint is incorrectly formed"
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Laravel 5.1 QueryException when trying to delete a project
- → Using Array in '->where()' for Laravel Query Building
- → Chaining "Count of Columns" of a Method to Single Query Builder
- → Laravel Eloquent Joining Strange query
- → convert time using mysql laravel 5
- → How to update a column after an expiration date in MySQL?
- → Foreign key constraint fails on existing key