Question about inserting/updating rows with MS SQL (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
4:52 UTC
Read the original article
Hit count: 132
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