Showing posts with label Sql Server. Show all posts
Showing posts with label Sql Server. Show all posts

Friday, February 18, 2011

How to re-insert deleted records when there is an identity field

My customers like to delete important records and then have me restore them from a backup when they realize their mistake.

When the column has an identity field, and you want to restore the records with the same number as they had before deleted, you must turn on identity insert with this TSql command

SET IDENTITY_INSERT {YourTableName} ON 

insert the deleted records

SET IDENTITY_INSERT {YourTableName} OFF 

Wednesday, January 19, 2011

How to create the ASP.Net membership tables

Sometimes web hosts (such as godaddy) will set up the aspnet membership tables for you in your database as part of the setup.

When you need to set them up locally, use the following .Net framework command
//For servername you can use "(local)" if the database is a local SQL Server install
System.Web.Management.SqlServices.Install(txtServer.Text, txtUserName.Text, txtPassword.Text, txtDatabase.Text, SqlFeatures.All);

Saturday, November 13, 2010

How to reseed an identity field

When I create e-commerce sites, the order numbers always start at 1. My customers like to pretend that they've had lots of orders when they launch, so I need to update their order number to something higher. The problem is this is always the identity field of the table. This command does the trick. It doesn't update the old order numbers, but I don't need those updated so it's no big deal.

DBCC CHECKIDENT('order', RESEED, 1000070 )