Assignment 9
Creation of database table using SQL in MS-Access.
SQL Server lets you use one command to quickly create a new table
containing a subset of records from a larger table. For example, suppose in
Access you want to create a phone list for all employees in the Fort Myers
region. To do this, you can create a new table containing only the records
of Fort Myers employees in the central Employee Records database. Follow
these steps:
1. Open the database containing the Employees table, then click
Queries in the objects list in the database window.
2. Click New | Design View | OK.
3. Click Close.
4. Go to Query | SQL Specific | Data Definition.
5. Enter the following statement:
SELECT [Employee ID], [Last Name], [First Name], Phone, City
INTO Phonelist
FROM Employees
WHERE City="Fort Myers"
6.Click Run.
A further complication: Because table creation is an action that could possibly
compromise database security, it’s disallowed by default. You must tell Access
that this is a trusted database before it will accept a data-definition query.
1. Clickthe Create tab on the Ribbon to display the icons for creation
functionality.
2. Click Query Design in the Queries section.
This displays the Show Table dialog box, which at this point contains
several system tables along with POWER.
3. Select POWER and click the Add button.
As you’ve seen in the previous example, a picture of the POWER table and
its attributes appears in the upper half of the work area.
Assignment 9
4. Click the Close button on the Show Table dialog box.
5. Click the Home tab and then the View icon at the left end of the Ribbon and
then choose SQL View from the drop-down menu that appears.
As in the previous example, Access has “helped” you by putting SELECT
FROM POWER in the SQL editor. This time you don’t want the help.
6. Delete SELECT FROM POWER and (in its place) enter the
data-definition query given earlier, as follows: