SQL Server Scripts to Create the Customer, Orders, ServicePlans, and Customer2 tables. Note: Be sure to follow each of these steps exactly to avoid errors. Make sure that you create a completely new database in the instructions below. DO NOT attempt to use an existing database. Creating the Database After you Connect in SQL Server Management Studio. Look to the left for a folder named Databases. Right click on the Databases folder and select "New Database". (See image below.)
Type the name of your database in the Database Name field and then click the OK button. (See image below.) Following are examples of potential database names: IntroductionToSQL, PracticeCourse, SQLCourse
Next, click the "New Query" button. (See image below.)
Next, select your Database from the "drop down box" near the top. (Instructions below.) To select a database in SQL Server use the drop-down list menu near the top of the screen. The default database is usually set to master. Use the drop-down menu to select the database that you created above. (See image below.) After your database is created and selected, you may execute the SQL script provided below to create and populate your tables. Please proceed to the instructions below.
Creating and Populating the Tables NOTE: Your database must already be created before proceeding with this step. (See above.) The SQL script to create and populate your tables must be executed in the white space provided on the right hand side of the SQL Server Management Studio interface. (See image below.)
Create and Populate the Customer Table To create and populate the Customer, Orders, ServicePlans, and Customer2 tables in SQL Server, you will use the SQL code in the links further below. You will create and populate each table one at a time. First, Click the Customer link below and Copy, Paste and Run (Execute) all of the SQL code (everything in the file) located in the Customer link below in your already created SQL Server database. Execute all (everything in the file) of the script at the same time. Copy and Paste the SQL code into the white space within SQL Server Management Studio and click the Execute button once in SQL Server Management Studio to execute (run) the SQL code. (See image below.) Note: Do not execute (run) the SQL script more than once. After executing the script you will receive messages stating 1 rows affected. This message is fine. It means that the statements were completed successfully.
Viewing Tables To view or open any table, type the following script (Replace the table name in the script to view different tables). Note: Delete any script within the white space query interface before performing this operation. For example, to view the Customer table, type the following script: (See image below.) SELECT * Click the Execute button to execute (run) the SQL script.
Create and Populate the ServicePlans Table Delete any script within the white space query interface. Click the ServicePlans link below and Copy, Paste and Run/Execute (Use the Execute Button) all of the SQL code (everything in the file) located in the ServicePlans link below in your already created SQL Server database. Execute all (everything in the file) of the script at the same time. Use the instructions above on Viewing Tables to open and view any of the tables. Note: Do not execute (run) the SQL script more than once. Create and Populate the Orders Table Delete any script within the white space query interface. Click the Orders link below and Copy, Paste and Run/Execute (Use the Execute Button) all of the SQL code (everything in the file) located in the Orders link below in your already created SQL Server database. Execute all (everything in the file) of the script at the same time. Use the instructions above on Viewing Tables to open and view any of the tables. Note: Do not execute (run) the SQL script more than once. Create and Populate the Customer2 Table Delete any script within the white space query interface. Click the Customer2 link below and Copy, Paste and Run/Execute (Use the Execute Button) all of the SQL code (everything in the file) located in the Customer2 link below in your already created SQL Server database. Execute all (everything in the file) of the script at the same time. Use the instructions above on Viewing Tables to open and view any of the tables. Note: The Customer2 table does not contain any data. We will populate this table later in the course. When you finish, you should have one database containing four tables.
Note: You will execute all of the SQL examples from the course in this interface (White space on the right hand side of SQL Server Management Studio). |