 Hey everybody, this is Brian. Welcome to the 49th lamp tutorial. Today we're going to be discussing inserting records. As you can see, I've got my database and I've got my tables. One of the tables is called TBL Products. In there I have a primary key, a description cost, and a date added. If we just go in here and we say alter table, you can see the types here. We have an int for the primary key, a var care 45 for the description, a double which is a number for the cost, and a date time for date added. I'm doing this just kind of to show you the nuances of adding things. So we're just going to right-click and send a SQL editor. We're going to select insert. I'm doing this to really save time so I don't have to type all this stuff out. Spend more time explaining it. Now we delete that first field because it's our primary key, the id tbl underscore products. You don't want to try to insert a primary key because it's already an auto increment field, meaning it's going to give you an error. These are on a one-to-one relationship meaning you have your column names and they must have a matching value. It's on one-to-one meaning the first one is the first one, the second one's the second one, so on and so forth. Notice how the names are in single quotes and for strings because we know that the description is a string that also needs to be in single quotes. So we're going to single quote that. We'll say name here cost. Numbers don't go into quotes so like we can say 99 cents. Date added. Now dates are tricky. Dates are an interesting one because they're not a string and they're not a number. They're a date. But in most databases you treat them as a string. So you put them in single quotes. Now there'll be another little trick to this where you have to know a special format. I'll say 2012, 24. So we've got year month day and we're just going to write a select statement just so we can see this actually work. We'll say select star from. Now real quickly what select does is it allows us to select records and actually view them and star as a wildcard means everything. So we're just going to select everything from the TBL products table in the My Store database after we have of course inserted our row here. So we'll execute this. There we go. And there is our first row. Now notice how we've got this zero zero zero zero zero zero zero. That is a timestamp. We have a date time. So it's a date and a time. So if you want the actual time you could actually get rid of that and just use a built-in function called now. And what now does is actually generates a date timestamp. So let's execute that. There it goes. Computers being funny for some reason. And here's our second row and you can see how we have a date timestamp. Now what happens if you want to do something like this? Bob's gun shop. Notice how it suddenly is complaining here. What's because of the single quote? We have to, you guessed it, escape the single quote by putting a forward slash in front of it. Now suddenly you can add this in. See, there's a single quote. If you forget to add that in, you will get an error message. That's pretty much all there is to the insert statement. It's pretty simple, pretty easy to understand. All you need to really remember when it comes to inserting is that you need to have a one-to-one relationship and the values have to be treated differently depending on what they are. For example, a string must be single quoted and you must escape single quotes. Numbers you never use a single quote. And for date times you can use a string format, meaning you use a single quote, or you can use the now function. That's all for this tutorial. Pretty simple one. Like I said, databases are not hard once you know how to use them.