Let's create some tables for the users, questions, and answers in our new database in SSMS:
- Copy the contents of the SQL Script at https://github.com/PacktPublishing/ASP.NET-Core-3-and-React-17/blob/master/Chapter07/backend/SQLScripts/01-Tables.sql
- In SSMS, with the QandA database highlighted, click New Query on the toolbar to create a new SQL query and paste in the contents from the copied script.
- Click the Execute option on the toolbar or press F5 to execute the query.
- If we look under Tables in Object Explorer, we should see that several tables have been created:
The following have been created:
- The Question table contains the questions that have been asked and contains the following fields:
- An integer-based field called QuestionId, which is the primary key Unicode-based Title and Content fields
- UserId and UserName fields, which reference the user who asked the question
- A field called Created, which will hold the date and time the question was asked
- The Answer table contains answers to the questions and contains the following fields:
- An integer-based AnswerId field, which is the primary key
- An integer-based QuestionId field, which references the question being answered
- A Unicode-based Content field
- UserId and UserName fields, which reference the user who answered the question
- A field called Created, which will hold the date and time the answer was submitted
- The SQL Script has added some example data. If we right-click on the Question table in Object Explorer and choose the Edit Top 200 rows option, we'll see the data in our table:
So, we now have a database that contains our tables with some nice data to work with.