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 |
|
fabianus76
Posting Yak Master
191 Posts |
Posted - 2006-01-04 : 16:40:19
|
| Hello !I would like to perform an insert into but I do not want SQL-Server (2005 Express) to bother if there is any conflict with an "unique"-index. Meaning that if a record might not be registered because of any conflict with an index, I want the query to be performed anyway, just by droping what is not possible to do. Thank you very much for any help!Regards, Fabianmy favorit hoster is ASPnix : www.aspnix.com ! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-01-04 : 16:43:03
|
| I am not following what you want. Do you only want to perform an insert if it doesn't exist already? Or do you want to perform and insert and don't care about the error if it does exist already? Please provide an example as some of the wording in your post is a bit confusing.Tara Kizeraka tduggan |
 |
|
|
fabianus76
Posting Yak Master
191 Posts |
Posted - 2006-01-04 : 16:51:42
|
quote: Originally posted by tkizer I am not following what you want. Do you only want to perform an insert if it doesn't exist already? Or do you want to perform and insert and don't care about the error if it does exist already? Please provide an example as some of the wording in your post is a bit confusing.Tara Kizeraka tduggan
Hallo Tara, thank you for the quick response!What I want to do is the follwing:Imagine you have a table with country names and this table has a unique index on the column of the country names. Now you want to add some new country names into your table. But your INSERT INTO will try to add some country names that are already existing in the table. Now with a normal INSERT INTO, the query won't be executed, but an error will be thrown back telling that there are some conflicts with the unique index on country names. So what I would like to do is to know if there is any T-SQL writing to add only the country names which are not yet existing in the table. Thank you for some further advice. Regards,Fabianmy favorit hoster is ASPnix : www.aspnix.com ! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-01-04 : 16:53:12
|
| How will the INSERT INTO be performed? Via SELECT or VALUES?Tara Kizeraka tduggan |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-01-04 : 17:02:06
|
Something like this should do it:insert into MyCountries (CountryName)select a.CountryNamefrom -- Table with new data MyNewCountries a left join -- Table you are inserting into MyCountries b on a.CountryName = b.CountryNamewhere -- make sure key not already in the table b.CountryName is null CODO ERGO SUM |
 |
|
|
fabianus76
Posting Yak Master
191 Posts |
Posted - 2006-01-04 : 17:13:39
|
| Hi tkizer, I want to perform via select.Hi Michael, thank you very much!Regards, Fabianmy favorit hoster is ASPnix : www.aspnix.com ! |
 |
|
|
|
|
|