Disabling Constraints in SQL server?
- Thread starter WWGD
- Start date
-
- Tags
- Constraints Server Sql
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 2K views
Discussion
Physics news on Phys.org
Mentor
- 15,788
- 10,667
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.
Science Advisor
Homework Helper
- 7,844
- 13,167
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.
Science Advisor
- 928
- 481
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?
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.
Mentor
- 4,789
- 3,854
Modern databases support sequences, a record field (part of the primary key) that is/can be automatically numbered on insertion by a predefined increment - usually one. This is specifically meant for repeating child tables. I think it is what @QuantumQuest is describing, but I am not sure - so I wrote this quick post.
Do not consider making a child table without keys unless it is VERY tiny and static. Then full table scans are sufficient and as fast as indexed column lookups.
Note: this defeats the purpose of most child tables.
Do not consider making a child table without keys unless it is VERY tiny and static. Then full table scans are sufficient and as fast as indexed column lookups.
Note: this defeats the purpose of most child tables.
Science Advisor
Homework Helper
- 7,844
- 13,167
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.
Similar threads
User-Defined Functions in Sql Server SSMS
- WWGD
- · Replies 7 ·
- Programming and Computer Science
- Replies
- 7
Python Any Experience with SQL Server Dev + Python& ML Server?
- WWGD
- · Replies 1 ·
- Programming and Computer Science
- Replies
- 1
Difference in order of execution and design in SQL Server.
- WWGD
- · Replies 3 ·
- Programming and Computer Science
- Replies
- 3
SQL Server modulo operator to find even numbers
- WWGD
- · Replies 7 ·
- Programming and Computer Science
- Replies
- 7
Amateur Dev Q: Creating Front End for SQL Server DB
- WWGD
- · Replies 18 ·
- Programming and Computer Science
- Replies
- 18
Can't find my Localhost Database Engine for SQL Server
- WWGD
- · Replies 3 ·
- Programming and Computer Science
- Replies
- 3
How Do You Implement Object_Definition with 2 Parameters in SQL Server?
- Pepper Mint
- · Replies 8 ·
- Programming and Computer Science
- Replies
- 8
How has SQL Server not gone the way of the dinosaur?
- SlurrerOfSpeech
- · Replies 3 ·
- Programming and Computer Science
- Replies
- 3
SQL Server OpenRowSet on Unknown Table
- Pepper Mint
- · Replies 1 ·
- Programming and Computer Science
- Replies
- 1
How to extract .mdf from .bak in SQL Server 2005
- EmerysMontgomery
- · Replies 1 ·
- Programming and Computer Science
- Replies
- 1