You can learn the grammar of a language in different ways:
1. Contact with native speakers, listening to the radio, watching television, reading magazines ... We all have an inborn mechanism for decoding and making sense of foreign languages; this is how we learned our mother tongue as a baby. By immersion in the foreign language and culture you should be able to pick up any language over a long period of time. When you acquire a language in this way, you learn the rules of the language (or grammar) just like native speakers do. You may not know the names of all the tenses, but you know how and when to use them.
2. Exercise practice. There are many types of excercises you can do to learn the grammar of a language. You can write out the exercises or repeat them orally (drills). The repetition of key structures helps you to remember them. There are also sentence completion, substitution and transformation exercises which allow you to manipulate the language and gain a greater understanding of how it works.
3. Studying a grammar designed for learners of the language. You need to find a book that meets your needs, with clear explanations of the rules and useful examples. This approach appeals to those who enjoy a logical and rational way of learning. In this way, you can learn how to form grammatically correct phrases, utterances and sentences, and when it is appropriate to use them. Unfortunately, the rules of formation and use are sometimes very complicated, and only really useful when you have the time to use them e.g. when writing.
4. Working out the grammar yourself. For those of you who like a challenge you can take a short phrase or text and try to work out the rules yourself. It is not as difficult as it seems, especially if you have a tutor to help you. You may also be surprised to find that some of the rules in your grammar book are only over-simplifications of the real rules. You can use a concordancer, a computer programme to help you analyse texts more easily. This approach is mainly recommended for students of linguistics and potential language teachers, to help them gain a deeper insight into syntactic complexity and the real rules of use.
Web of Grammars - lots of online grammars for many languages