One of the utmost commonly asked questions by SQL server database programmers is how to change the format a datetime value into a specific date format. Convert can used to cpnvert a date to varchar format like below Here’s a summary of the different date formats that come standard in SQL Server as part of […]
We can use the Haversine formula To calculate distance between two points assuming that we have Latitude and longitude values for both the points. The formulas are based on spherical earth, so there might not be accurate since the earth is sligthly ellipsoidal.
Update T-SQL statement is used to change data in one or more columns in database. You can issue an UPDATE statement against a table or updateable view, as long as the statement modifies data in only one base table at a time. An UPDATE statement must always include a SET clause, which identifies the columns […]
We could use SP_RENAME system stored procedure to rename any user created data object such as column, table, index, data type in SQL Server. Syntax: Sample Data: I have created a simple table tblTest and added a unique index on column “NAME”. Example 1: Rename table tblTest to tblTest2 Example 2: Rename column […]
In this article, I would explain how to perform table and column operations using SMO objects. You could refer to following articles for more SMO examples. Create Database using SMO (SQL Management Object) Backup and Restore SQL Server Database Programmatically in C# SMO Assemblies: Add reference to following assemblies in your project. They should already […]
DOTNET provides SQL Server Management Objects (SMO) to customize and manage SQL Server management applications. SMO extends and supersedes SQL Server Distributed Management Objects (SQL-DMO) which was used for SQL Server 2000. In this article, I would be explaining on how to take create & drop SQL Server database Even though we can perform these […]
DOTNET provides SQL Server Management Objects (SMO) to customize and manage SQL Server management applications. SMO extends and supersedes SQL Server Distributed Management Objects (SQL-DMO) which was used for SQL Server 2000. In this article, I am going to explain how to backup restore SQL Server Database programmatically. SMO classes can be categorized into two […]
In my previous blogs, I have outlined about copying data from one sql server database to other and from a excel file to sql server database. In this article, I would be discussing about importing data from a flat file (with headers and delimited data) to SQL Server. Overview SqlBulkCopy is a class that was […]
I have seen so many requests by so many users asking for WHILE LOOP construct. It is as simple as writing a while loop in any programming language. While loop sets a condition for the repeated execution of an SQL statement or statement block. The statements are executed repeatedly as long as the specified condition […]
What are identity columns?
IDENTITY is a property you could set on a table. You could only set this property on one column in the entire table. SQL Server will take care of incrementing this column based on the seed you gave while creating the property.
IDENTITY [ ( seed , increment ) ]
Seed — Is the value that is used for the very first row loaded into the table.
Increment — Is the incremental value that is added to the identity value of the previous row that was loaded.
Default values – (1,1)
1. An Identity column is not guaranteed to be unique nor consecutive.
2. If any insert failure is there then also it can change the current seed value.
3. If we truncate a table (but not delete), it will update the current seed to the original seed value.