sqlschool.gr logo

articles

Articles of SQLschool.gr Team

List all IDENTITY Columns in your database

Antonios Chatzipavlis
Monday 16 November 2015

Συνεχίζοντας από το τελευταίο μου άρθρο σήμερα θα σας παρουσιάσω ακόμα ένα metadata query με το οποίο θα μπορώ να γνωρίζω τα tables που έχουν IDENTITY column, το data type που έχουν αυτές οι columns όπως επίσης από που ξεκινάνε (seed) πως μεγαλώνει η τιμή του (increment) και ποια είναι η τρέχουσα τιμή του.

Το παρακάτω metadata query μπορείτε να καταναλώστε ελεύθερα σε όλες τις εκδόσεις του SQL Server καθώς έχω φροντίσει να χρησιμοποιήσω τα information_schema views και όχι τα system views που στο πέρασμα των εκδόσεων έχουν μικρές ή μεγάλες αλλαγές.

Φυσικά αν κάποιος θέλει περισσότερες πληροφορίες μπορεί να χρησιμοποιήσει απευθείας τα system views αλλά ίσως να αυτό που θα φτιάξει σε μια έκδοση να μην δουλεύει σε επόμενη ή προηγούμενη έκδοση.
select 
        TABLE_SCHEMA
,        TABLE_NAME
,        COLUMN_NAME
,        DATA_TYPE
,        IDENT_SEED(TABLE_SCHEMA+'.'+TABLE_NAME) AS SEED_VALUE              
,        IDENT_INCR(TABLE_SCHEMA+'.'+TABLE_NAME) AS INCR_VALUE                  
,        IDENT_CURRENT(TABLE_SCHEMA+'.'+TABLE_NAME) AS CURRENT_VALUE
from INFORMATION_SCHEMA.COLUMNS 
where COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME),COLUMN_NAME,'IsIdentity')  = 1
ORDER BY 1,2
results

Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios Chatzipavlis is a highly experienced Data Solutions Consultant and Trainer. He has been working in the IT industry since 1988, holding various roles such as senior developer, IT Manager, Data & AI Solutions Architect and Consultant.

Since 1995, Antonios has focused on modern technologies and software development tools, primarily by Microsoft. He has specialized in Data & AI since 2000, with expertise in Microsoft Data Platform (SQL Server, Azure SQL Databases, Azure Synapse Analytics, Microsoft Fabric, Power BI, AI) and Databricks.

Antonios is also a Microsoft Certified Trainer (MCT) for over 25 years, has been recognized as a Microsoft Most Valuable Professional (MVP) in Data Platform since 2010 and he is in the Data Expert 40 Powerlist 2024 by Boussias. He is the co-founder and visionary behind XLYTiCA, a company dedicated to Data & AI solutions.

Episode

Task Flows in Microsoft Fabric

image

More Episodes...

Tip

What's New in SQL Server 2022 - Episodes

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2025 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.