Skip to main content

Posts

Showing posts from October, 2014

Running .Sql file from command prompt

In this article I am demonstrating the running the .sql files form command prompt. Step -1 create the table using the sql management studio. CREATE TABLE tbl_Student ( ID INT IDENTITY ( 1 , 1 ) PRIMARY KEY , Fname VARCHAR ( 100 ), Lname VARCHAR ( 100 ), Salary INT ) Step-2 INSERT INTO tbl_Student ( Fname , LName , Salary ) VALUES ( 'Rakesh' , 'Kalluri' , 10000 ) INSERT INTO tbl_Student ( Fname , LName , Salary ) VALUES ( 'Srujan' , 'Kumar' , 15000 ) INSERT INTO tbl_Student ( Fname , LName , Salary ) VALUES ( 'Raju' , 'Bhai' , 17000 ) INSERT INTO tbl_Student ( Fname , LName , Salary ) VALUES ( 'Dany' , 'Mark' , 18000 ) The above script file is saved in Desktop with the file name of Student.sql . The file is saved in desktop now just we need to run the file from command prompt. Step-3 Go to run - -> Type CMD - → Click OK ...

How to Reset identity column values in sql server

Here is the sample demonstration for reset identity column value Step-1 : Create table CREATE TABLE dbo . Emp ( ID INT IDENTITY ( 1 , 1 ), Name VARCHAR ( 10 ) ) Step-2 :Insert some sample data INSERT INTO dbo . Emp ( name ) VALUES ( 'Rakesh' ) INSERT INTO dbo . Emp ( Name ) VALUES ( 'Rakesh Kalluri' ) When we run above query the second insert statement will failed because of varchar(10) length. Step-3 :Check the identity column value DBCC CHECKIDENT ( 'Emp' ) Even second insert was failed but the identity value is increased .if we insert the another record the identity value is 3 INSERT INTO dbo . Emp ( Name ) VALUES ( 'Kalluri' ) SELECT * FROM Emp Step-4: Reset the identity column value DELETE FROM EMP WHERE ID = 3 DBCC CHECKIDENT ( 'Emp' , RESEED , 1 ) INSERT INTO dbo . Emp ( Name ) VALUES ( 'Kal...