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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 INSERT record

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-19 : 14:59:11
Hello,

I have a table named Ratings with 4 columns:
id, name, userid and docid

userid and docid are FKs and PK of table Users and Docs

How can I insert a record in table ratings?

And is it possible, and is usually done, to output a error variable which says if a user or a doc was not found?

Thanks,
Miguel

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-03-19 : 15:03:04
You haven't given much information, so here is a basic insert statement for your table:
INSERT INTO Ratings (id, name, userid, docid)
VALUES (@id, @name, @userid, @docid)

If that's not what you want, then you need to provide more information.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-19 : 15:19:23
Let me try to explain better. Usually I have a Feedback ouput parameter where I save some error or message code.

For example:

-- Find label with given LabelId
IF EXISTS (SELECT * FROM dbo.Labels WHERE LabelId = @LabelId)
BEGIN

-- Delete label
DELETE
FROM dbo.Labels
WHERE LabelId = @LabelId

-- Delete error
SELECT @Feedback = @@ERROR

END
ELSE

-- Label not found
SELECT @Feedback = -1

So in the case I described I will check if a UserId or DocId exists in the other tables ... if any of those do not exist I would just return a error code in my @Feedback output parameter.

Is this a good approach to deliver some feedback to my .NET code?

This way in my .NET code I check the Feedback value and determine which message to display.

Thanks,
Miguel
Go to Top of Page
   

- Advertisement -