Skip to main content

Creating Database with some tables in Sql Server step by step

SQL Database and Tables Creation step by step

We have installed Sql Server in our previous post here, now we are going to see how to create database and its table in sql server.

Steps below show how to create a database and its tables, but we need to install Sql Server Management Studio for Graphical User Interface program to create and maintain databases.

Now download and install the Sql Server Management Studio here, after installing the software, we connect to the sql server using the Management Studio as shown below

Click on the connect button as shown above after selecting the Server type, Server name and Authentication.

Server Type: allows you to select the server type such as Database Engine, Reporting Services or Integration Services. But in post, we are living it with the default Server type that is, Database Engine.

Server name: Let us select the server we are connecting to, we also allow the default since we have only one instance.

Authentication: This allows us choose which authentication to use, either Windows Authentication or SQL Server Authentication.

Windows Authentication allows us to use the windows Login details to connect to the database server.

SQL Server Authentication enable us to provide the Username and Password set during SQL Server installation Process.
After successful connection to the Database Server, we have the below window displayed.


From the above image, we can now see Server Explorer which shows some of the database objects and default folders such as Databases folder, Security Folder, Server Object Folder, Replication and the rest.

Our concern in the post is on Databases folder. Let us expand it and see what it contained.
As we can see below, it contained the previously created Databases

Let us now create a new Database called csharpnaija_employees.
Right click on the Databases folder and click on New Database as shown below


Enter the name of the database and click on ok as shown below

Now our database is created successfully. We can now see the database we created in list of the databases in the server explorer.


Now let us create our tables in the database created. These tables are employees and departments.

Now expand the database that we just created named csharpnaija_employees
From the list of folders in the expanded table, we can see that we have Tables folder and others
To create a new Table, right click on the Tables folder, select new and click on Table… as shown below.

Enter the Column name, Data type and either allow null or not as shown in the image below

The column names are as follows;
First Name, Middle Name, Last Name, Address, Phone Number, Date of Birth, Department Id

After entering the columns as shown above, we need to specify the primary key of the table.
To make the Id field as the primary key of the table, we right click on the Id column and click on set Primary Key as shown below

To make the Id as auto incremented primary key, click on the Id field, go to the columns properties below the table properties, scroll to Identity Specification, double click on the Identity Specification and double click on ‘Is Identity’ .

Finally, to save the table, press ctrl s on your keyboard to save the table and provides the table name as shown below.

Enter the name of the table as employees and click on ok as shown below

We now have a table named employees in the csharpnaija_employees database as shown below
Repeat the same procedures for creating table, to create the second table named departments as shown below
To add records to the tables created, we right click on the departments table and click on Edit Top 200 Rows as shown below

These are some of the records added to the Departments table as shown below

To add records to the emloyees table, right click on the Employees table and click on Edit Top 200 Rows as shown below

The data entered into Employees table are shown below


Comments

  1. Thank you Tutor. It's really educative sir.

    ReplyDelete
    Replies
    1. Youre welcome, just making it easier for people to be programmers

      Delete

Post a Comment

Popular posts from this blog

Classes in C# Explained

C# Class Explained A class is nothing but an encapsulation of properties and methods that are used to represent a real-time entity, as explained by Guru99 . For instance, if you want to work with Guest’s data as in our previous DataDriven Web application . The properties of the Guest would be the Id, GuestName, Address, Phone number etc of the Guest. The methods would include the entry and modification of Guest data. All of these operations can be represented as a class in C# as shown below. using System; namespace CsharpnaijaClassTutorial {     public class Guest     {         public int Id { get ; set ; }         public string GuestName { get ; set ; }         public string Address { get ; set ; }         public string WhomToSee { get ; set ; }     ...

ASP.NET MVC Views

Views in ASP.NET MVC Application explained Find a related article By  Steve Smith  and  Luke Latham from Microsoft Corporation here In the Model-View-Controller (MVC) pattern, the  view  handles the application's data presentation and user interaction. A view is an HTML template with embedded  Razor markup . Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET MVC, views are  .cshtml  files that use the  C# programming language  in Razor markup. Usually, view files are grouped into folders named for each of the application's  controllers . The folders are stored in a  Views  folder at the root of the application as shown: The  Home  controller is represented by a  Home  folder inside the  Views  folder.  The  Home  folder contains the views for the  About ,  Contact , and  Index...

ASP.NET MVC Routing

ASP.NET MVC Routing ASP.NET MVC routing is a pattern matching system that is responsible for mapping incoming browser requests to specified MVC controller actions. When the ASP.NET MVC application launches then the application registers one or more patterns with the framework's route table to tell the routing engine what to do with any requests that matches those patterns. When the routing engine receives a request at runtime, it matches that request's URL against the URL patterns registered with it and gives the response according to a pattern match. Routing pattern is as follows A URL is requested from a browser, the URL is parsed (that is, break into controller and action), the parsed URL is compared to registered route pattern in the framework’s route table, if a route is found, its process and send response to the browser with the required response, otherwise, the HTTP 404 error is send to the browser. Route Properties ASP.NET MVC routes are res...