Monday, October 27, 2014

Working on graduation project and geting some usefull code

I've been rather chilling last 1 month and a half from the last subject I had to finish, before I could start a graduation project. Last couple of weeks I am working on it and I will make a post about it when it is finished. I am doing it with MVC ASP.NET C# so for now!

I wanted to share one usefull code that helped me for MVC database. I got a need where I am entering users into database, to reset the auto-increment number to a specific number. Meaning, whenever you create a new user, you will have its own ID number being auto increased by 1. However since I created couple of users named with "asdasdjqw" and "ajsfiaosfj" I had to delete them, but when I do that the numbers are going to increase by 1.

This means that if you had ID numbers up to 15, your ID database table would look like:

0  NameUser
1  NameUser2
16 NameUser3

Where 0,1,16 are ID numbers. So I wanted to get back to 0,1,2 and continue from that. And I came to this line of code, that worked quite good.

dbcc checkident( 'Users' , RESEED , 1 )

Where Users is my database table. Once you execute this query and create a new user, it will continue following the order of 0,1,2,3,4,5 and so on.

Hope this is some usefull info for MVC users who are just begining. Have fun!