From the course: SQL Server 2014 Essential Training

Creating a table using Managment Studio - SQL Server Tutorial

From the course: SQL Server 2014 Essential Training

Start my 1-month free trial

Creating a table using Managment Studio

- In this section, we're gonna talk about creating tables. And tables are very important in a database. Almost all of the data stored in a database is stored in tables. And the tables define the structure and format of the data. So here in SQL Server Management Studio, I'm gonna open up the LyndaDemo database. I'll right click on Tables, the top option is New, and I'll say Table. In the interface presented, I'm first asked to provide a column name. So for this demo, we'll be creating a table that holds information about people, and we'll want to store things like first name and last name. So I'll call the column, firstName. And for the Data Type, I'm going to be putting text into this column obviously. The SQL language has many different ways to store text. One of the most common is the varchar, which roughly stands for variable length characters. And in this case, it defaulted to 50. So this column would hold a maximum of 50 characters, which is plenty enough for a first name. And variable length means the database will only use the amount of space necessary to hold whatever data we give it. So if we only input 10 characters, it will only reserve space for 10 characters, with a maximum of 50. The varchar Data Type does not accept unicode characters, if we want to use unicode characters, then we'll need to go with the nvarchar, and that would accept unicode characters. We also have a checkbox on the end on whether or not to allow nulls. In other words, whether or not to allow blank values. I'm going to clear that checkbox. Then in the next row, I'll type in another column name. This column will be used to hold the data for the last name. So I'll call it lastName. And I'll use the same Data Type, nvarchar(50). And again, not going to allow nulls. This interface doesn't really allow me to name the table, that happens when I close the dialog. It says would I like to save it, and I'll say yes. And at that point, I am prompted for a name of the table. And I'll just call this table, People. And now if I open up my list of tables, right click and hit refresh, I'll see a new table called People. There's a handful of different ways to get data into that table. The easiest of which might be to right click and go to Edit Top 200 Rows. And in the interface that comes up I can just type in first names and last names. And when I'm done with that, I'll close the dialog. And again I'll right click on the name of the table. And I'll choose Select Top 1000 Rows, and we'll see all of the data in that table returned to us, and it is exactly what we just typed in. So great, we have a table, and we were able to insert some data into it, and then we were able to retrieve that data.

Contents