Question about inserting/updating rows with SQL Server (ASP.NET MVC)

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-06-15T04:45:26Z Indexed on 2010/06/15 5:12 UTC
Read the original article Hit count: 128

Filed under:
|
|
|

I have a very big table with a lot of rows, every row has stats for every user for certain days. And obviously I don't have any stats for future. So to update the stats I use

UPDATE Stats SET Visits=@val WHERE ... a lot of conditions ... AND Date=@Today

But what if the row doesn't exist? I'd have to use

INSERT INTO Stats (...) VALUES (Visits=@val, ..., Date=@Today)

How can I check if the row exists or not? Is there any way different from doing the COUNT(*)?

If I fill the table with empty cells, it'd take hundreds of thousands of rows taking megabytes and storing no data.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql-server