You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a query to generate Pks of tables. The code is below:
SELECT DISTINCT
KCU.TABLE_SCHEMA
,KCU.TABLE_CATALOG
,KCU.TABLE_NAME
,'ALTER TABLE '+KCU.TABLE_SCHEMA + '.' + KCU.TABLE_NAME
+' CONSTRAINT '+ KCU.CONSTRAINT_NAME
+' PRIMARY KEY ("'+lower(KCU.COLUMN_NAME)+'");' as GENERATE_PK
FROM INFORMATION_SCHEMA.TABLES T
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE as KCU ON
T.TABLE_SCHEMA = KCU.TABLE_SCHEMA
AND T.TABLE_NAME = KCU.TABLE_NAME
AND T.TABLE_CATALOG = KCU.TABLE_CATALOG
AND OBJECTPROPERTY(OBJECT_ID(KCU.CONSTRAINT_SCHEMA + '.' + QUOTENAME(KCU.CONSTRAINT_NAME)), 'IsPrimaryKey') = 1
WHERE T.TABLE_CATALOG = '%information_schema.database_name%'
AND T.TABLE_TYPE = 'BASE TABLE'
AND T.TABLE_NAME NOT IN ('dtproperties')
ORDER BY 1,2,3;
I hope this code help you to increase your solution.
Tks.
`
The text was updated successfully, but these errors were encountered:
It's a great tool, however in my case all tables were generated without primary keys.
I'm using SQL Server 2012 and PostgreSQL 12.
Is there any way to correctly generated primary keys and foreign keys?
Hi,
I made a query to generate Pks of tables. The code is below:
I hope this code help you to increase your solution.
Tks.
`
The text was updated successfully, but these errors were encountered: