There should be no set age, and definitely not just one discussion about such things. In fact you should be careful even trying to set hard and fast rules.
The biggest problem when it comes to sex and sexuality with children is getting children to speak to, and listen to, parents. There are many reasons for this, like kids thinking it's gross or embarrassing to discuss with their parents. The biggest issues are that parents usually teach children to not discuss these things through many subtle indicators that they are not comfortable discussing sexuality. This usually happens through many tiny subtle instances of parents shushing children when they talk about 'embarrassing' things as a little child, which all combines to teach children that they just can't talk about certain subjects with their parents; making them embarrassed to do so later even if you want them to.
A second issue with teens is that they often think their parents are disconnected and don't 'get it' and are inclined to dismiss parental advice as being a theoretical thing that doesn't really apply to their real lives. This can be a particular issue because many times parents do set unreasonable expectations on their children. Teenagers are interested in relationships, dating, and yes sex. Expecting them to be a nun with no dating until 18 and never even thinking about sex until their married is just not realistic. Trying to push a perfect idealized approach to sex and dating on a child, even if some of it is quite reasonable to an adult, will seem insane to a teenage child; and too strict of rules will simply be dismissed as adults not 'getting it' and ignored.
Incidentally as someone who has advice allot of teens, you would be amazed how much a little bit of the "yeah, those dumb adults I know most of them totally don't get it. Good thing I'm not like them, now let's talk honestly" tactic can get teens to at least hear you out.
The first step to teaching proper sexual views and dialogue is to address the issue of dialogue. You need a child to be able to speak about sex and sexuality with you if you are to teach them. To do this you want to make a child know that they can talk to you about such things! This means encouraging an open discussion from a very young age. If a child asks questions you find mildly embarrassing like "where do babies come from?" or "why do women have breasts and men don't?" or "why is daddies penis bigger then mine?" or "why does mommies vagina have hair around it and mine doesn't?" you need to answer the questions honestly, and without embarrassment. This is so very important! If you respond with embarrassment or shush them the kids will learn they can't talk to you about 'private' stuff, and that lesson will stick with them subconsciously so their uncomfortable talking about sex or dating when older. Honest and frank answers when their child goes so far towards keeping the dialog open.
You can teach a child that some questions should be asked in private, if your afraid of having to answer embarrassing questions in public. It's okay to say "I'll answer that question when we get home". However, make sure you actually do answer the question at home, even if they forgot about it, so they know you mean it when you say "were talk later" and that your not just trying to shush them from asking.
As the child gets older you can now start to teach sex and sexuality more freely by answering questions as they ask them. Ideally you will be the first one they come to to ask when they should hold hands, who to kiss, or what should a kid do when they take another kid 'out on a date'. It's important to always encourage such questions. Done right you will never have to sit down to discuss exact rules or expectations, instead the child will be asking you about such things as they get to the age that they are interested.
Also, do not tease kids about things like dates, or at least don't only tease them about it. Be supportive of their 'dates' when their little kids who don't understand what a date really is, and don't tease them about liking a girl. Too much teasing will also teach a preteen not to talk to you or your just tease them. Some teasing may be allowed, depending on child and parental relationship, but only if it's done after a more honest and supportive discussion, not before or without one.
You can also start up discussions about things you feel they are ready to discuss, if the child doesn't ask, but be very careful not to make it 'THE TALK". When I say start a discussion I don't mean sit them down one day and spend 2 hours explaining sex, sperm, tiny eggs, pregnancy, and STDs to a 12 year old; that will just leave them confused and lost.
There should never be just one discussion covering everything. When I say start up a discussion I mean mention one tiny important fact they may be ready to know. For instance if you have a family member who is pregnant you may use it as an excuse to start telling them a bit about where babies come from (Uncle mike and aunt Lisa love each other and want a baby, so they decided to have one, and now Aunt Lisa is pregnant with a baby growing in her. When people love each other they do something called 'sex' to get pregnant like Aunt Lisa so they can be mommy and daddy). Yes I said the S word there, it's important that they not thing words like sex, penis, or vagina are 'bad words' they can never say. In that example not much was explained, and that's fine. What your want is for the child to start asking questions from there. For instance when you say that aunt Lisa was pregnant because of sex the kid may say "isn't that a bad word". Then you can explain that sex is not bad, it's just something that people do in private and some don't like talking about; but they can always ask you about it. Or, if the child is older, explain that sex is fine when done with two people who love each other, it's only bad if done before your ready or with someone you don't love.
The point is though that you should look at ways to start a discussion about subjects, but not dictate how the conversation goes. As they get older you can start discussing their interest in boys or girls, or their puberty and curiosities that come with it etc. Start the discussion, and let them lead it! Just be open to answering their questions. Also, don't be afraid to answer with everything they are capable of understand, and maybe just a little more then they may get now. What you don't want to do is constantly over-simplifying because your afraid they won't understand. Too much over simplifying once the child is old enough to understand more will lead them to not bothering to ask because they won't get a full answer.
If your child is older and that dialogue doesn't already exist it can make it harder to form one now, but not impossible. Start discussing simple stuff now. I would not leap straight into the sex talk or dictating sexuality immediately, warm them up by talking about their date or who they have crushes on, or if they are uncomfortable with that start more general. You need to develop a dialogue by finding what they are willing to talk about and discussing it openly and non-judgmentally, so they will open up to discuss more stuff as time goes on. Forcing them to talk about things they find clearly embarrassing once, then never touching on the subject again, will not work; they will just see it as an embarrassing discussion they try to forget.
The other half of the discussion is being realistic in what you tell your children you expect. If you act unable to understand what they are going through, or always tell them exactly how they must behave without thought to what they are thinking or feeling, they will be far less likely to trust your advice. In general rules without reasons are much harder for any child to accept.
If you are going to set boundaries start by explaining exactly why you feel that boundary needs set, and be honest about it. Don't try scare tactics like "your get an STD if you even think about doing anything with that boy", because teens quickly recognize these as scare tactics and once they do they will not listen to you afterwards since you aren't being honest. However, you can explain that usually teens are happier waiting to have sexual relations, that pregnancy is a major risk they must be aware of, and yes there are also STDs; just don't make STDs into the unrealistic bogy man to scare kids straight some try to. In any case explain your reasoning, including listening to your child's feelings about those reasons.
Your child will be young and naive and will not like to be told that no, they don't know everything at age 17 and that boy they just met a week ago is probably not really the love of their life. Try to be understanding and not condescending to them. Yes you will likely have to eventually fall back on the fact that they are young, and they may not have the perspective to understand what their feeling yet, but don't completely dismiss their feelings or emotions when doing so if you want them to feel like your listening and giving honest advice.
The biggest mistake you can make with older teens is being unrealistic. They are quick to dismiss parents as foolish and naive, and they have peers with so much wonderful 'advice', often much of it foolish. The problem is they trust their peers, even when their peers are idiots. You must prove you can be trusted as well! Do not lie, or mislead, or exaggerate! You must also try to toe a careful line between explaining what you expect, and being judgmental if the child doesn't meet that expectation.
To give the most obvious example, none of us wants our 17 year old child having sex; but statistically speaking by 17 they will be having sex! You can explain why you want them to wait, why it's smart and best, and that you will be upset if they don't. However, if they know you will do nothing but yell, scream, and disown them if they have sex they will likely still have sex, most teens do, and simply not tell you. Which means you can't put your daughter on birth control, or explain to your son how to properly get and use condoms (you would be amazed how foolishly teens use birth control; they have no one to explain how to do it right!).
What you need is for your child to know that they can talk to you. If they decide to have sex that they can come and speak with you about it. It's far FAR more important that they get birth control if they have sex. For that matter if a child is going to have sex they still have the ability to decide who it is with. Maybe you can't talk them out of experimenting, but at least you can make sure they respect themselves and their partner if they do go that route. In any case the point is that you can not always prevent the child from doing something like this, even if you are right and they are being foolish. Thus it's important to set a careful balance between setting rules, and explaining that you want the child to speak with you even if they aren't going to listen to your rules. Which is why I would suggest only a few of the most important rules, and most of the rest be strongly worded advice. In other words, you let them know they can break the advice and still speak with you; even as your stress as hard as you can why you really don't want them to, and why it's best they listen to you.
That sounds like allot of advice, but the good news is that it's not as hard to do in practice as it sounds. In short simply be open to answering questions and never shy away from embarrassing topics. Make your child know they are allowed to speak with you. Just don't condescend or dismiss their curiosities; useful advice about all questions not just sexual ones.
The only difficult part is once they reach teenage years trying to provide strong advice while still letting the child know they can talk to you no matter what. I suggest explicitly saying, a few times, that they can talk to you whatever they decide.
Tangentially related, I suggest making birth control available for children of both sexes from a relatively young age. I want kids to wait, but they usually don't. Better to protect them if they don't listen. Besides, If done well it can show that your available to listen to them honestly about stuff like sex without just yelling at them to not have it, even as you still advice against it.