Answer the question
In order to leave comments, you need to log in
How to add to a database table without repeats?
I have a table. I fill it with students. Then I delete some rows from the table. How can I add only those lines that have been removed? If you fill in the primary key again, then there will be an error that such ones already exist. And if you turn it off, then there will be duplicates.
Answer the question
In order to leave comments, you need to log in
insert into Students
select list.Id, list.[Name]
from
(values
(1,N'Вася'),
(2,N'Петя'),
(3,N'Женя'),
(4,N'Коля'),
(5,N'Настя'),
(6,N'Аристарх'),
(7,N'Никодим')
) list (Id, [Name])
left join Students s on s.Id = list.Id
where s.Id IS NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question