I am trying to create a duplicate table in SQL SERVER. I changed the table name but all other objects like constraints are same. Do i have to change all the objects as they exists in the base table or i can have same objects name?
I know it might sound a silly question but i am new to this.
Sql-server – Creating Duplicate Table in SQL SERVER 2014
sql servertable
Related Question
- Methods for identifying differences in accumulating history table
- Oracle SQL Creating Copy of Table Using DBMS_metadata
- Sql-server – De-duplicate rows in place vs de-duplicate on transfer
- Sql-server – Duplicate all stored procedures with a new name
- Sql-server – Sql server – The provided statistics stream is corrupt
- Sql-server – duplicate key error creating unique index on temp, SQL Server 12.0.5589 bug
Best Answer
Explicitly named constraints must be uniquely named within a database.
If they are not unique, you'll see errors like this:
This is especially pertinent for creating #temp tables. Never specify the name of a constraint when creating a #temp table, since concurrent executions of the code will fail with the above error.
Take for example:
The command fails because
PK_SomeTable
is defined twice, once in each table. However, if we re-code the 2nd statement:Now, it works.
For #temp tables, you'd use the following construct: