Locked lesson.
About this lesson
We will create a new database within MS SQL Server 2016, and create a new table
Quick reference
Creating a New Database
Creating a new database is point and click easy.
When to use
Do this every time you create a new database.
Instructions
- In the object explorer, right click on the Database folder and select "New Database".
- Type a name for your new database and click "ok".
- That's it!
Once you create a database, add a Table to it by right clicking on Tables --> New. The Tables folder will be a sub-folder under the new database folder you created, which in our case, is called Customers.
Please Note: Since this lesson was originally published, the 'text' datatype has been deprecated. Choose varchar(50) instead for each text column.
Hints & tips
- Creating a new database is point and click easy.
- Right click the Database folder in the object explorer and choose "New Database"
- Name it and Click "Ok"
- 00:05 Okay, now it's time for the fun stuff.
- 00:06 In this video, we're gonna actually create our first database.
- 00:09 And before I do that,
- 00:10 I should mention I can create a whole course on database design.
- 00:14 Sort of the logic that goes behind building a database.
- 00:17 And by that I mean, what kind of columns should we have?
- 00:19 How many should we have?
- 00:20 What should they be named?
- 00:21 What kind of data should we put in?
- 00:23 You can go very deep and get very intricate in that sort of thing, and
- 00:26 we're not going to dive into that in this course.
- 00:28 I'm just gonna show you the basis of how to build a simple database,
- 00:31 and we're just gonna dive in and do it.
- 00:33 But sort of keep that in mind, there's ways to design these things logically
- 00:37 as you get more advanced, but right now, we just need to build something.
- 00:40 So to do that, to create our first database,
- 00:43 we just right click on this database folder.
- 00:45 Click on new database.
- 00:47 And let's name this.
- 00:48 And let's call it customers.
- 00:50 Sticking with the same theme that we had several videos ago,
- 00:52 with our Excel spreadsheet.
- 00:53 We're just going to call this customers.
- 00:55 So we don't have to do anything else.
- 00:56 The owner is default.
- 00:57 Keep everything like that.
- 00:58 Click okay.
- 00:59 And then if we expand this, boom.
- 01:03 We've got our customer database.
- 01:05 So now we can expand that.
- 01:07 And we got all kinds of stuff here.
- 01:09 We don't care about any of this stuff at this point, but
- 01:12 if we expand this table, we have system tables, file tables, external tables.
- 01:16 Bunch of stuff that was automatically created for us.
- 01:19 Again, we don't care about any of this stuff.
- 01:20 We need to create our own table.
- 01:22 So remember back to the Excel video, where we had a database.
- 01:26 And inside that database, we had tables.
- 01:28 And inside those tables, we had columns and rows.
- 01:30 So we've got the database, it's customers, now we need to create a table.
- 01:34 So right-click on Tables and click New, and then Table.
- 01:39 And right here, we can start designing the columns and rows for this table.
- 01:43 And you notice we haven't named the table yet.
- 01:46 We'll do that later on.
- 01:47 Whenever we save this thing it'll ask us for a name.
- 01:50 Right now we just need to create our columns.
- 01:52 So, let's create a first name, and you hit tab to go to the data type,
- 01:57 and remember like I said a few videos ago, each column has to have a name and a data
- 02:01 type, and it's going to default, sort of tell you what it thinks it should be.
- 02:05 And this is in character.
- 02:07 So it's saying, ten characters.
- 02:10 That might be okay, ten is a little bit short for a name.
- 02:13 First names generally aren't more than ten letters long, so you're probably okay, but
- 02:17 you can change it to anything you want.
- 02:18 And you see this drop down box?
- 02:20 Here are the different data types, all of them, that you can choose from.
- 02:23 We talked about data types a couple of videos ago, so we have big integers,
- 02:27 bits, characters, dates, date/time.
- 02:29 And you can look each of these up individually if you want to learn
- 02:32 exactly what all of these things are.
- 02:34 You sort of can, int is the one you're going to use for numbers, for
- 02:37 the most part.
- 02:38 N char.
- 02:39 That N stands for Unicode, remember.
- 02:41 So we don't really care about Unicode.
- 02:43 I might go varchar50.
- 02:45 That's variable character.
- 02:48 Of 50 characters.
- 02:49 50 is definitely enough letters for most first names.
- 02:52 Or you could go max, whatever you want.
- 02:54 See, there's just a plain text we might pick.
- 02:57 We'll just do that.
- 02:57 So then, let's create another one, last name,
- 03:00 and I I hit T on my keyboard and it automatically went to text.
- 03:04 And we'll use a couple of different data types in this table as we go throughout
- 03:07 the course.
- 03:08 And we can see how they work.
- 03:09 Any limitations they might have.
- 03:11 For example, we're using text data right here and the text has a number of
- 03:15 limitations In terms of what will work with it and things like that.
- 03:18 In reality you might wanna use the var char data type instead of text.
- 03:23 And in a later lesson we'll actually learn how to change between
- 03:26 different data types.
- 03:27 So if you pick text and it doesn't work and you wanna switch to var char we'll
- 03:30 show you how to do that using the alter table and alter column command.
- 03:34 And let's go email address, and
- 03:38 let's go change it around, let's go char 50, let's say, what else do we have?
- 03:42 We had email address, we had phone number, I hit tab accidentally.
- 03:49 Phone Number, now let's go text again.
- 03:53 Age, let's go int.
- 03:55 And Street Address, let's go text again.
- 04:01 So, now we have our table here and we can come over here and we can click name and
- 04:05 we can change it like this.
- 04:06 Or we can just close this, and it'll ask us for a name.
- 04:09 But I'm going to go over here and click, and
- 04:10 I'm going to call this one current_customers.
- 04:12 That's what we called it in the Excel video.
- 04:16 So, we've pretty much done everything we need to do.
- 04:18 We've designed our database, and we're good to go.
- 04:21 So, if we come up here and click this little X this is the little close button.
- 04:26 It will ask us if we want to save this and we click yes and
- 04:29 if we haven't named it at this point it will ask us for a name at that point or
- 04:33 it will just use a default and you can go back and change it later.
- 04:36 But now one thing to note if we look through here.
- 04:39 We go to our customer and our tables, it doesn't show up yet.
- 04:43 We have to come up here and click this refresh button and
- 04:45 then boom current customers.
- 04:48 We can expand this if we want current customers, it has been created.
- 04:51 So that's as easy as it gets, that's how we created a database,
- 04:55 we've created a new table.
- 04:57 In the next video I'll show you how to add to that table.
Lesson notes are only available for subscribers.