Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
datanalyst
Starting Member
3 Posts |
Posted - 2011-07-21 : 10:03:48
|
| Hello All,I want to insert data to an existing table In SQL Server Database. Some of these data I want to add on this table has the same Primary Key e.g EmpID which is the Primary Key Column has an already existing record Emp0020.Thank you.Doka |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-21 : 10:05:04
|
| You can't have a duplicate PK.Do you want to do an update (merge)?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-21 : 10:05:54
|
| If it is the primary key, you cannot insert duplicates. Part of the reason for the existence for a primary key is to prevent such duplicates. You can update the existing row - if that is what your business logic requires. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-21 : 10:08:45
|
| or you could add a new key column (maybe an id value) and then make it pk after dropping existing pk if you want to accomodate this data too. but for this you need to be careful on dependencies and should do impact analysis before going with it. there was definitely a reason why it was chosen as a pk in first place so make sure you check if this is absolutely required.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
datanalyst
Starting Member
3 Posts |
Posted - 2011-07-21 : 10:36:05
|
quote: Originally posted by datanalyst Hello All,I want to insert data to an existing table In SQL Server Database. Some of these data I want to add on this table has the same Primary Key e.g EmpID which is the Primary Key Column has an already existing record Emp0020.Thank you.Doka
Thank you all for your fast response.I thought so. I will drop the Primary Key and add Incremental ID on this table since it is not linked to other tables.Thank youDoka |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-07-21 : 11:53:41
|
| Please post DDL with specs and not narratives or an invented language. We need keys, DRI actions, and constraints. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. Let us know if you can changed the DDL >> I want to insert data to an existing table In SQL Server Database. Some of these data I want to add on this table has the same PRIMARY KEY e.g emp_id which is the PRIMARY KEY Column has an already existing record [rows are not records] 'Emp0020'. <<OF COURSE NOT! Read the definition of a PRIMARY KEY in any book on RDBMS or SQL. Why did youj even ask this question?--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|