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

The String.Join Method in C# Explained

The String.Join Method in C#   The string.Join concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. Overloads of string.Join Method Description Join(Char, Object[]) Concatenates the string representations of an array of objects, using the specified separator between each member. Join(Char, String[]) Concatenates an array of strings, using the specified separator between each member. Join(String, IEnumerable<String>) Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member. Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element. Join(String, String[]) Concatenates all the elements of a string array, usi...

Models in ASP.NET MVC

Models in ASP.NET MVC Explained A model is a class that contains the business logic of your application. It also used for accessing data from the database. The model class does not handle directly input from the browser. In MVC, it is the Controller that handle input from the browser directly and process the request by receiving data from the model and pass it back to view as response. It does not contain any HTML code either. It is a best practice but not mandatory for developers to not have any communications with the view directly, models should only contain a POCO ( Plain Old CLR Objects ) classes. All processing logic and communication with the view should be handled by another layer called Viewmodels. Models are also refers as objects that are used to implement conceptual logic for the application. A controller interacts with the model, access the data, perform the logic and pass that data to the view. Note that it is not mandatory, but it is a good programming...

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 ; }     ...