我一直在网上搜索,这个查询应该有效:
INSERT INTO Groep(Naam) SELECT ? WHERE NOT EXISTS (SELECT * FROM Groep Where Naam=?)
但它没有..我得到一个OleDbException
:
关键字“DEFAULT”附近的语法不正确
我一直在网上搜索,这个查询应该有效:
INSERT INTO Groep(Naam) SELECT ? WHERE NOT EXISTS (SELECT * FROM Groep Where Naam=?)
但它没有..我得到一个OleDbException
:
关键字“DEFAULT”附近的语法不正确
尝试这个 :
INSERT INTO TableName (ColumnName) SELECT '" + value + "' WHERE NOT EXISTS ( SELECT ColumnName from TableName WHERE Name = '" + value + "')";
后跟一个 ExecuteNonQuery()。
假设数据库是 SQL Server ...
创建唯一键
Alter Table TableName ADD CONSTRAINT ConstraintName PRIMARY KEY (ColumnName)
If Not Exists(Select PrimaryKey From TableName Where ColumnName = 'Value')
Begin
Insert Into TableName(Columns....)
Values(......)
End
Declare @Var int
select @Var = column1 from TableName Where Column2 = 'Value'
if(@Var is null)
Begin
Insert Into TableName(Columns....)
Values(......)
End