Tags:

    Tips for using Visual Studio to Access your database:

    Previous Lesson: Establishing connection to your SQLSERVER database:

    1. How to create a table?
      1. Visual studio provides a GUI similar to MS Access for accessing SQL server database. To create a table, right click on subfolder table and choose add new table. You can then create a table in the same way as you did for Access. 
    2. How to create a view or a query?
      1. To create a view, go to Server Explorer, right click on subfolder view, and choose new view. This will open a QBE window similar to MS Access where you can define a view and save it. 
      2. To create a query, go to Server Explorer, right click on subfolder view, and choose new query. However SQL Server does not ask if you want to store the query when you close the query window. The query will go away if you close the query window. 
    3. How to create relationships between tables?  
      1. In Server Explorer, right-click the table that will be on the foreign-key side of the relationship and click Open Table Definition.
      2. The table opens in Table Designer. Note from this point the procedure is identical to using MS SQL Server Management Studio Express.OpeningTableDefinitionVS2008.tiff
      3. From the Table Designer menu, click Relationships.ViewingRelationsVS2008.tiff
      4. In the Foreign-key Relationships dialog box, click Add.
      5. The relationship appears in the Selected Relationship list with a system-provided name in the format FK_<tablename>_<tablename>, where tablename is the name of the foreign key table.
      6. Click the relationship in the Selected Relationship list.
      7. Click Tables and Columns Specification in the grid to the right and click the ellipses () to the right of the property.tablesAndColumnsSpecSelectVS2008.tiff
      8. In the Tables and Columns dialog box, in the Primary Key drop-down list, choose the table that will be on the primary-key side of the relationship.tablesAndColumnsSpecVS2008.tiff
      9. In the grid beneath, choose the columns contributing to the table's primary key. In the adjacent grid cell to the left of each column, choose the corresponding foreign-key column of the foreign-key table.
      10. Table Designer suggests a name for the relationship. To change this name, edit the contents of the Relationship Name text box.
      11. Choose OK to create the relationship.
    4. If your are using JDBC, you can stop here and proceed to the Web Objects - EO Modeler segments.
    5. If you are generating scripts running via VS 2008 and wish to generate scripts that will produce the same database, then follow these steps.
      1. You must have a database project created in a solution to generate a Create script. To create a new database project, from the File menu, click New Project and in the New Project dialog box, under Project Types open the Other Project Types node. Click Database, and in the Templates window click the Database template icon. Name the solution and then click OK
      2. In Server Explorer, right-click the database object (e.g. table) for which you want to generate create scripts.
      3. go to View -> Solution Explorer, you can double click on database objects to view generated scripts.
    6. How to connect to my SQL Server database using Access?
      1. Open Access, File->New ->Project using existing data, the following dialog will show. Enter the same database connection information. 
      2. Click OK, you will see all the database objects you’ve created in your SQL Server database. 
      3. Using Access as front end, you can:
        1. Insert, Update, and delete data in the table
        2. Create forms to manipulate data in the table
        3. Create Reports
      4. However, you can not:
        1. Change table definitions
        2. Change view definitions
        3. Create new views on SQL Server