How are trading account, demat account and bank accounts linked?

How are trading account, demat account and bank accounts linked?