• How to create a Database in ASP.NET MVC

    by  • January 8, 2016 • Microsoft SQL Server • 0 Comments

    Visual Studio IDE comes with a free SQL database called SQL Server. When a user fill the form and submit it we have to save the data submitted in a database. Here we will discus, how to create database for saving user’s data. We will create a database and add a table in that database in this article.

    Database can be created with the following simple steps.

    1. Right click the App_Data folder in the Solution Explorer
    2. Select Add, then select new item
    3. Select SQL Server Database
    4. Name the Database like BookStore.mdf
    5. Click the Add button

    After database has been created, double click on the database or press Ctrl + Alt + S to open server explorer as shown in the figure below;

    database new       Server Explorer

    Now we will create a table where data submitted by the user will be stored. Go to sever explorer, expand the folder then right click on the Table folder. Click on Add New Table and then by T-SQL command of Create Table, we are creating table as shown in the code below;

    We are creating four columns in the table Book. The first three columns AuthorName, Title, PublisherName are text columns having datatype Varchar and the fouth column PublishDate has datatype Date to store publish date. Here we declare the AuthorName as Primary Key.

    After adding a table, click on Update link on the top left corner. A new window ‘Preview Database Updates’ will open as shown below;

    UpdateDatabase message

    Click on update Database and a message will appear that shows update completed successfully as shown above. So in this way, we are creating a new table in our database ‘BookStore’.




    Namecheap.com

    Leave a Reply