WebApr 30, 2009 · 9 Answers Sorted by: 417 Here you go: SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME = 'X' AND REFERENCED_COLUMN_NAME = 'X_id'; If you have multiple databases with similar tables/column names you may also wish to limit your query to a particular database: WebJul 10, 2016 · List Primary Key Columns. To list the Primary Key columns, I used SQL Server’s implementation of the ANSI standard Information Schema Views as they’re easier to work with: there’s no need to use the object_name() function to translate object_ids to human-readable names.. I use [INFORMATION_SCHEMA].[KEY_COLUMN_USAGE] to …
SQL - Inserting a row and returning primary key - Stack Overflow
WebMar 10, 2024 · From the MySQL documentation: If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row. This approach doesn't only work with primary keys, it also works with any column having a unique index. Share … WebDec 7, 2013 · A better way is to use SHOW KEYS since you don't always have access to information_schema. The following works: SHOW KEYS FROM table WHERE Key_name = 'PRIMARY' // Column_name will contain the name of the primary key. Share Follow answered Dec 7, 2013 at 22:20 Stoic 10.4k 6 40 60 Thanks! franke saphira coffee machine
php - 獲取mysql中刪除的主鍵列表 - 堆棧內存溢出
WebFeb 9, 2024 · A better way to get Primary Key columns: SELECT `COLUMN_NAME` FROM `information_schema`.`COLUMNS` WHERE (`TABLE_SCHEMA` = 'dbName') AND (`TABLE_NAME` = 'tableName') AND (`COLUMN_KEY` = 'PRI'); From http://mysql-0v34c10ck.blogspot.com/2011/05/better-way-to-get-primary-key-columns.html Share … WebTo create a PRIMARY KEY constraint on the "ID" column when the table is already created, use the following SQL: ALTER TABLE Persons ADD PRIMARY KEY (ID); To allow … WebFeb 22, 2024 · when I try to get inserted primary keys, and I am getting: AttributeError: 'MySQLExecutionContext_mysqldb' object has no attribute 'inserted_primary_key', but topic_res is 'ResultProxy' object due to debug. ... DBAPI doesn't support this and the mysql adapters don't appear to offer any non-standard APIs for this. franke shop online