In this lesson, you create a simple table called Names, which contains two columns that have the following properties:
Column name | Data type | Allow null? | Default | Primary key? |
---|---|---|---|---|
ID | UUID | No | None | Yes |
Name | Varchar(254) | No | None | No |
Add a DataAccess method to create the table.
private void createDatabaseSchema() { try{ _conn.schemaCreateBegin(); ColumnSchema column_schema; TableSchema table_schema = _conn.createTable("Names"); column_schema = table_schema.createColumn( "ID", Domain.UUID ); column_schema.setDefault( ColumnSchema.COLUMN_DEFAULT_UNIQUE_ID); table_schema.createColumn( "Name", Domain.VARCHAR, 254 ); IndexSchema index_schema = table_schema.createPrimaryIndex("prime_keys"); index_schema.addColumn("ID", IndexSchema.ASCENDING); _conn.schemaCreateComplete(); } catch( ULjException uex1){ System.out.println( "ULjException: " + uex1.toString() ); } catch( Exception ex1){ System.out.println( "Exception: " + ex1.toString() ); } } |
If the table already exists, an exception is thrown.
Call the DataAccess.getDataAccess method.
Uncomment the call to createDatabaseSchema in the sample code from Part 1, Lesson 3, Step 3. The call to createDatabaseSchema should look like the following:
_da.createDatabaseSchema() |
Run the application again in the simulator.
When you alter the table schema, for example, by adding a table definition, you must keep the following information in mind:
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |