Use the newpubs database you created in the previous section to try these examples. Otherwise, these changes will affect another database, like pubs2 or pubs3.
The simplest form of | create| table| is:
create table table_name (column_name datatype)
For example, to create a table named names with one column named some_name, and a fixed length of 11 bytes, enter:
create table names (some_name char(11)) drop table names
If you have set quoted_identifier on, both the table name and the column names can be delimited identifiers. Otherwise, they must follow the rules for identifiers described under “Identifiers”. Column names must be unique within a table, but you can use the same column name in different tables in the same database.
There must be a datatype for each column. The word “char” after the column name in the example above refers to the datatype of the column—the type of value that column will contain. Datatypes are discussed in Chapter 6, “Using and Creating Datatypes.”
The number in parentheses after the datatype determines the maximum number of bytes that can be stored in the column. You give a maximum length for some datatypes. Others have a system-defined length.
Put parentheses around the list of column names, and commas after each column definition. The last column definition does not need a comma after it.
You cannot use a variable in a default if the default is part of a create table statement.
For complete documentation of create table, see the Reference Manual.
Copyright © 2005. Sybase Inc. All rights reserved. |