It doesn't have to be right away, nor is it likely that it would be if it were granted. There are a lot of things going on, and it looks almost certain that if an independent Scotland becomes a reality that they'd have to apply to the EU as a new nation, assuming that's even what people in Scotland want to do at the end of it all. Given all this it's likely that a new referendum would take place around the time the UK leaves the EU, most likely after we leave the EU. Then people can decide what they want to do once they know the situation regarding Brexit, and have a better feel for the likely outcome of a Scottish EU application, or if they even want to make one.