कमांड "pragma table_info ('tablename')" कॉलम की जानकारी और "pragma foreign_key_list ('tablename')" विदेशी कुंजी सूचीबद्ध करता है। मैं तालिका के अन्य बाधाओं (चेक, अद्वितीय) को कैसे प्रदर्शित कर सकता हूं? केवल "sqlite_master" तालिका के "sql" फ़ील्ड को पार्स कर रहा है?SQLite में किसी तालिका की बाधाओं को पाने का कोई तरीका है?
11
A
उत्तर
6
मुझे लगता है कि ऐसा करने का एकमात्र तरीका यह है कि आपने सुझाव दिया है, sqlite_master डेटाबेस के एसक्यूएल कॉलम को पार्स करें।
अजगर कोड यह करने के लिए:
import sqlite3
con = sqlite3.connect("example.sqlite3")
cur = con.cursor()
cur.execute("select sql from sqlite_master where type='table' and name='example_table'")
schema = cur.fetchone()
con.close()
entries = [ tmp.strip() for tmp in schema[0].splitlines() if tmp.find("constraint")>=0 or tmp.find("unique")>=0 ]
for i in entries: print(i)
3
+7
सभी इंडेक्स बाधाएं नहीं हैं, और सभी बाधाएं इंडेक्स नहीं हैं। –
वहाँ भी "pragma index_list ('TableName')" है देखें http://www.sqlite.org भी
pragma index_list('tablename')
नहीं है /pragma.html#pragma_index_list – Nabab
@ नाबाब आपको वास्तव में यह जवाब देना चाहिए कि उत्तर –