-1

i'm at the very start of learning about how to code and started from SQL and Python. I have a task: to list all primary keys in data base. How can I do it? Diagram I used

 select * from public

But it returns with error

1 Answers1

-1

This the query will list all the primary keys for a SQL Server database:

select * from sys.objects where type = 'PK'
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nayan
  • 164
  • 7
  • 1
    Do not post code-only answers, add an explanation to your code. And not all databases have the same system tables, so this is not a cathall solution – astentx Feb 07 '21 at 08:56
  • 1
    To be clear: this will provide a list of the primary key **constraints** in the current SQL Server database. It does **not** provide the name of the columns in those constraints, nor does it list the **values** in those columns – marc_s Feb 07 '21 at 10:00