- 7,806
- 13,120
Hi, I want to practice queries that require having repeated records. This is not allowed by default since it violates uniqueness constraint. Do I just use an alter table drop unique constraint for this?
The discussion centers around the topic of managing uniqueness constraints in SQL Server, particularly in the context of practicing queries that involve duplicate records. Participants explore methods for creating tables that allow repeated records, the implications of removing uniqueness constraints, and the potential use of identity columns for testing purposes.
Participants express differing views on the best methods for handling uniqueness constraints and the implications of allowing duplicate records. There is no consensus on a single approach, and multiple perspectives are presented regarding the use of identity columns and the performance of tables without uniqueness.
Limitations include the assumption that participants are discussing non-production environments for testing purposes. There are also unresolved details regarding the specific methods for removing duplicates and the implications of altering table structures.
Thanks, I am trying to use them to test certain queries, like queries done to delete duplicates. So for this, I need to have duplicates which I can then delete.jedishrfu said:Can’t you build a table without the uniqueness? I’ve done that from time to time. These kinds of tables are slower if large and you need to find stuff. You want to avoid table scans that’s why indexes were created.
WWGD said:Hi, I want to practice queries that require having repeated records. This is not allowed by default since it violates uniqueness constraint. Do I just use an alter table drop unique constraint for this?
Yes, this is just small-scale academic effort; I would not experiment in a production environment. Thanks.QuantumQuest said:If the table you want to have duplicate records in has a unique identification column (some sort of an "ID" thing) then (obviously) there is no problem inserting duplicate records or even more than two times the same record. So, I think that you mean that you don't have something like this and hence the uniqueness constraint issue you talk about. In this case - as far as I know, you need to have permission for an "ALTER TABLE" in order to add an identity column. Then you can utilize one of various methods to get rid of the duplicate records i.e. correlated subquery, using temporary table etc. (for these various methods you may want to take a look here). Needless to say that all the above are for testing purposes on a table that you can really alter without affecting the database schema i.e. not on any sort of database in production phase.