we indicate that the name column in the people table must be unique we also indicate that the combination of the two numbers in each row of the follows table must be unique these constraints keep us from making mistakes such as adding the same relationship more than once we can take advantage of these constraints in the following codecur execute('''insert or ignore into people (nameretrievedvalues ? )'''friendwe add the or ignore clause to our insert statement to indicate that if this particular insert would cause violation of the "name must be uniquerulethe database system is allowed to ignore the insert we are using the database constraint as safety net to make sure we don' inadvertently do something incorrect similarlythe following code ensures that we don' add the exact same follows relationship twice cur execute('''insert or ignore into follows (from_idto_idvalues (??)'''(idfriend_idagainwe simply tell the database to ignore our attempted insert if it would violate the uniqueness constraint that we specified for the follows rows retrieve and/or insert record when we prompt the user for twitter accountif the account existswe must look up its id value if the account does not yet exist in the people tablewe must insert the record and get the id value from the inserted row this is very common pattern and is done twice in the program above this code shows how we look up the id for friend' account when we have extracted screen_name from user node in the retrieved twitter json since over time it will be increasingly likely that the account will already be in the databasewe first check to see if the people record exists using select statement if all goes well inside the try sectionwe retrieve the record using fetchone(and then retrieve the first (and onlyelement of the returned tuple and store it in friend_id if the select failsthe fetchone()[ code will fail and control will transfer into the except section friend ['screen_name'cur execute('select id from people where name limit '(friendtry in generalwhen sentence starts with "if all goes wellyou will find that the code needs to use try/except