How to Create a SQL Server Database

Download ArticleDownload Article

SQL Server databases are some of the most common databases in use, thanks in part to how easy it is to create and maintain them. With a free graphical user interface (GUI) program such as SQL Server Management, you don't need to worry about fumbling around with the command line. See Step 1 below to create a database and start entering your information in just a few minutes.

  1. How.com.vn English: Step 1 Install the SQL Server Management Studio software.
    This software is available for free from Microsoft, and allows you to connect to and manage your SQL server from a graphical interface instead of having to use the command line.
    • In order to connect to a remote instance of an SQL server, you will need this or similar software.
    • Mac users can use open-source programs such as DbVisualizer or SQuirreL SQL. The interfaces will be different but the same general principles apply.[1]
    • To learn how to create databases using command-line tools, see this guide.
  2. How.com.vn English: Step 2 Start up SQL Server Management Studio.
    When you first start the program, you will be asked what server you would like to connect to. If you already have a server up and running, and have the permissions necessary to connect to it, you can enter the server address and authentication information. If you want to create a local database, set the Database Name to . and the authentication type to "Windows Authentication".
    • Click Connect to continue.
    Advertisement
  3. How.com.vn English: Step 3 Locate the Database folder.
    After the connection to the server, either local or remote, is made, the Object Explorer window will open on the left side of the screen. At the top of the Object Explorer tree will be the server you are connected to. if it is not expanded, click the "+" icon next to it. Located the Databases folder.[2]
  4. How.com.vn English: Step 4 Create a new database.
    Right-click on the Databases folder and select "New Database...". A window will appear, allowing you to configure the database before creating it. Give the database a name that will help you identify it. Most users can leave the rest of the settings at their default.[3]
    • You will note that as you type the database name, two additional files will be created automatically: the Data and the Log file. The data file houses all of the data in your database, while the log file tracks changes to the database.
    • Click OK to create the database. You will see your new database appear in the expanded Database folder. It will have a cylinder icon.
  5. How.com.vn English: Step 5 Create a table.
    A database can only store data if you create a structure for that data. A table holds the information that you enter into your database, and you will need to create it before you can proceed. Expand the new database in your Database folder, and right-click on the Tables folder and select "New Table...".
    • Windows will open on the rest of the screen which will allow you to manipulate your new table.
  6. How.com.vn English: Step 6 Create the Primary Key.
    It is highly recommended that you create a Primary Key as the first column on your table. This acts as an ID number, or record number, that will allow you to easily recall these entries later. To create this, enter "ID" in the Column Name field, type int into the Data Type field, and uncheck the "Allow Nulls." Click the Key icon in the toolbar to set this column as the Primary Key.
    • You don't want to allow null values because you always want the entry to be at least "1". If you allow nulls, your first entry will be "0".
    • In the Column Properties window, scroll down until you find the Identity Specification option. Expand it and set "(ls Identity)" to "Yes". This will automatically increase the value of the ID column for each entry, effectively automatically numbering each new entry.
  7. How.com.vn English: Step 7 Understand how tables are structured.
    Tables are composed of fields or columns. Each column represents one aspect of a database entry. For example, if you were creating a database of employees, you might have a "FirstName" column, a "LastName" column, an "Address" column, and a "PhoneNumber" column.
  8. How.com.vn English: Step 8 Create the rest of your columns.
    When you finish filling out the fields for the Primary Key, you will notice that new fields appear underneath it. These allow you to enter in your next column. Fill out the fields as you see fit, and ensure that you pick the right data type for the information that will be entered in that column:
    • nchar(#) - This is the data type you should use for text, such as names, addresses, etc. The number in parentheses is the maximum number of characters allowed for this field. Setting a limit ensures that your database size stays manageable. Phone numbers should be stored with this format, as you don't perform mathematical functions on them.
    • int - This is for whole numbers, and is typically used in the ID field.
    • decimal(x,y) - This will store numbers in decimal form, and the numbers within the parentheses denote the total number of digits and the number digits following the decimal, respectively. For example decimal(6,2) would store numbers as 0000.00.
  9. How.com.vn English: Step 9 Save your table.
    When you are finished creating your columns, you will need to save the table before entering information. Click the Save icon in the toolbar, and then enter in a name for the table. Naming your table in a way that helps you recognize the contents is advisable, especially for larger databases with multiple tables.
  10. How.com.vn English: Step 10 Add data to your table.
    Once you've saved your table, you can begin adding data to it. Expand the Tables folder in the Object Explorer window. If your new table is not listed, right-click on the Tables folder and select Refresh. Right-click on the table and select "Edit Top 200 Rows".[4]
    • The center window will display fields for you to begin entering data. Your ID field will be filled automatically, so you can ignore it right now. Fill out the information for the rest of the fields. When you click on the next row, you will see the ID field in the first row fill automatically.
    • Continue this process until you've entered all the information you need.
  11. How.com.vn English: Step 11 Execute the table to save the data.
    Click the Execute SQL button on the toolbar when you are finished entering the information to save it to the table. The SQL server will run in the background, parsing all of the data into the columns you created. The button looks like a red exclamation point. You can also press Ctrl+R to execute as well.
    • If there are any errors, you will be shown which entries are filled out incorrectly before the table can be executed.
  12. How.com.vn English: Step 12 Query your data.
    At this point, your database has been created. You can create as many tables as you need within each database (there is a limit, but most users will not need to worry about that unless they are working on enterprise-level databases). You can now query your data for reports or any other administrative purposes. See this guide for detailed information on running queries.
  13. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Under the terms of hardware, how do you build a server?
    How.com.vn English: Community Answer
    Community Answer
    A server is just like any other computer. Its hardware is just more suited for the rigours of a server environment and server tasks. Thus, server hardware may have lots of drives, dedicated network cards, redundant power supplies, and lots of RAM.
  • Question
    Do laptops have the SQL software?
    How.com.vn English: Community Answer
    Community Answer
    Usually not preinstalled, do a search for "Microsoft SSMS" and download, it's about a 700 mb file for the newest version.
  • Question
    How do I access a new SQL database remotely from a newly built desktop?
    How.com.vn English: Community Answer
    Community Answer
    It will works exactly the same. Unless you plan to buff it up later, you should do these exact tasks.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      About This Article

      Tested by:
      How.com.vn Technology Team
      How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 19 people, some anonymous, worked to edit and improve it over time. This article has been viewed 1,003,777 times.
      How helpful is this?
      Co-authors: 19
      Updated: April 29, 2023
      Views: 1,003,777
      Categories: Software
      Article SummaryX

      1.Install SQL Server Management Studio.
      2.Select a server and click Connect.
      3.Click + on the database server.
      4.Click New Database.
      5.Enter a database name and click OK.
      6.Right-click the database and select New Table.
      7.Create the Primary (int) key in the first row.

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 1,003,777 times.

      Reader Success Stories

      • How.com.vn English: Jennie Segee

        Jennie Segee

        Dec 16, 2017

        "I am new to database creation, so I am taking a college class on the subject. One of our assignments is to create a..." more
      Share your story

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement