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 |
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.
Add the following code before the method returns:
_da.createDatabaseSchema(); return _da; |
When you alter the table schema, for example, by adding a table definition, you must keep the following information in mind:
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |