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

Friday, September 21, 2018

Check the current Identity and Reset the Identity

Code Snippet:



// Check the current identity of the table
SELECT IDENT_CURRENT('tablename') 


 //Reset the identity to next incremental value
DBCC CHECKIDENT ('tablename', RESEED, 0)




When RESEED is used then the numbervalue in third argument of the CHECKIDENT is set as current identity for the table. Here in this case RESEED to 0 means 



Friday, March 23, 2018

Sql Server: Get count of * or distinct rows for column A grouped by column B

Scenario 1 - count of * rows:

A table has 10 records. Column B has duplicate rows with different values in Column A

then., Sql Query:


Code Snippet:
SELECT COUNT(ColumnA) AS Count_Headertext,
ColumnB AS ColumnB_Headertext
FROM Tablename
GROUP BY ColumnB



Scenario 2 - count of distinct rows:

A table has 10 records. Column B has duplicate rows with different values in Column A

then., Sql Query:


Code Snippet:
SELECT COUNT(DISTINCT ColumnA) AS Count_Headertext,
ColumnB AS ColumnB_Headertext
FROM Tablename
GROUP BY ColumnB