|
|
8000XXXX Errors ASP.NET 2.0 Classic ASP 1.0 Databases Access DB & ADO General SQL Server & Access Articles MySQL Other Articles Schema Tutorials Sql Server 2000 Sql Server 2005 General Concepts Search Engine Optimization (SEO)Search | ASP FAQ Tutorials :: Databases :: Schema Tutorials :: Schema: How do I show all the primary keys in a database? Schema: How do I show all the primary keys in a database?SQL Server This query will return all of the primary keys, including those with multiple columns (and will return those in the order they are listed in the key definition):
You can also use the following methods:
sp_pkeys will return a row for each column that participates in the primary key for <tablename>. The columns you are likely most interested in are COLUMN_NAME and PK_NAME. sp_helpconstraint will list all constraints for <tablename>, including foreign keys that reference the table. In the first recordset, there will only be a column called Object Name (kind of useless, since that's what you passed in). In the second resultset, there will be the following columns: constraint_type, constraint_name, and constraint_keys. Microsoft Access This code uses ADOX to iterate through all the primary keys:
Related Articles Schema: How do I list all the indexes in a database? Schema: How do I list the databases on my server? Schema: How do I show all the triggers in a database? Schema: How do I show the columns for a table? Schema: How do I show the description property of a column? Schema: How do I show the parameters for a function or stored procedure? Schema: How do I show the stored procedures in a database? Schema: How do I show the tables in a database? Schema: How do I show the user-defined functions (UDFs) in a database? Schema: How do I show the views in a SQL Server database? |