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 |
|
shaik.zakeer
Posting Yak Master
117 Posts |
Posted - 2008-08-30 : 06:21:32
|
| HelloI have a table called vehicle maker.create table vehicle_maker(id int identity(1,1),maker_name varchar(20))data avaliable id maker_name1 Hyundai2 TATAif i insert again the existing maker_name it should allow to insert.If its not avaliable in the table it should commit the transaction.When ever someone is inserting values in this table how can i do this validation.How can i check whether the record is avaliable or not.thanks in advanceThanks Zakeer Sk |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-30 : 09:57:17
|
Use a trigger or set a unique constraint on maker_name. the trigger will be a INSTEAD OF INSERT trigger likeCREATE TRIGGER CheckValue ON [vehicle maker]INSTEAD OF INSERT ASIF NOT EXISTS(SELECT 1 FROM INSERTED i INNER JOIN [vehicle maker] v ON v.maker_name=i.maker_name)BEGIN INSERT INTO vehicle_maker(id,maker_name) SELECT id,maker_name FROM INSERTEDEND |
 |
|
|
shaik.zakeer
Posting Yak Master
117 Posts |
Posted - 2008-09-01 : 08:13:36
|
| ThanksThanks Zakeer Sk |
 |
|
|
|
|
|