Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to insert null values basing on count ???
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

252 Posts

Posted - 01/03/2013 :  08:04:44  Show Profile  Reply with Quote
i have a table A

in which data look like this

userid documentid name
1 1 mohan

1 2 raj

1 3 majuu

2 1 raj

2 2 jey

2 3 lol

so we can observe user id 1 have 3 document id(1,2,3) so how to insert 4 and 5 records when userID 1 have 3 records if it have 3 rd record inserted simultaneously 4 and 5 th record should inserted through procedure can any one suggest me ???


Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 01/03/2013 :  08:27:43  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
How are the rows inserted?
Do you mean if there is an insert for a user id that has 2 roes then you want an extra two added?

Obvious options are
Insert via a stored procedure, count the rows then insert the extra 2 if there are 3 rows. It will need to be in a transaction.
Create a trigger for insert. If the count is 3 for the user then add the extra 2 rows.

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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000