This lesson assumes you have completed all preceding lessons. See Lesson 1: Designing the schemas.
This lesson guides you through the following steps to set up your SQL Anywhere consolidated database:
Connect to the consolidated database.
Create the CustomerProducts tables and alter the Customers table to include regional information.
Prepare the consolidated databaseClick Start » Programs » SQL Anywhere 12 » Administration Tools » Sybase Central.
Click Connections » Connect With SQL Anywhere 12.
Perform the following tasks in the Connect window:
In the Action dropdown list, choose Connect With An ODBC Data Source.
In the ODBC Data Source Name field, type SQL Anywhere 12 Demo.
Click Connect.
Connect to your consolidated database in Interactive SQL.
At a command prompt, run the following command:
dbisql -c "DSN=SQL Anywhere 12 Demo" |
In Interactive SQL, execute the following statements to create and insert data in the CustomerProducts table:
CREATE TABLE CustomerProducts
(ID int default AUTOINCREMENT PRIMARY KEY,
SalesOrderID int NOT NULL,
CustomerID int NOT NULL,
ProductID int);
INSERT INTO CustomerProducts (SalesOrderID,CustomerID,ProductID)
SELECT SalesOrders.ID, SalesOrders.CustomerID, SalesOrderItems.ProductID
FROM SalesOrders, SalesOrderItems
WHERE SalesOrders.ID = SalesOrderItems.ID; |
In Interactive SQL, execute the following statements to add regional information for each customer to the Customers table:
ALTER TABLE Customers
ADD Region VARCHAR(255);
UPDATE Customers
SET Region = (SELECT TOP 1 SalesOrders.Region
FROM SalesOrders
WHERE Customers.ID = SalesOrders.CustomerID
ORDER BY Region); |
Adding unique primary keys
See also![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |