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

Most Popular Programming Languages in 2020

Most Popular Programming Languages in 2020 In this blog post, you will learn about the most popular programming languages in 2020 for creating the best web applications. Check its pros and cons. Analyzed by technostacks Not very long ago, just a few people were considered to be computer programmers, and the general public viewed them with awe. In this digital age that we are now living in, however, a large number of IT jobs need a solid grasp of one or more programming languages. Whether one wants to develop a mobile app or get a certification for having programming knowledge, or even to learn new skills, one needs to opt for the right programming language. Below mentioned eight most popular programming languages which are in demand for software development and web applications. This is the most used programming languages in 2019 and will be in 2020. For each, there is little information about the language, benefits and its complexity, as well as about its usage. One must...

HashTable in C# with Example

  HashTable in C# with Example Hashtable  is used to store a collection of key/value pairs of different  data types  and are organized based on the hash code of the key.   Generally, the hashtable object will contain buckets to store elements of the collection. The bucket here, is a virtual subgroup of elements within the hashtable and each bucket is associated with a hash code, which is generated based on the key of an element.   In C#, hashtable is same as a  dictionary  object but the only difference is that the  dictionary  object is used to store a key-value pair of same  data type  elements.   When compared with  dictionary  object, the hashtable will provide a lower performance because the hashtable elements are of object type so the boxing and unboxing process will occur when we are storing or retrieving values from the hashtable.   C# HashTable Declaration Hashtable is a non-generic type...