Datatypes of columns, variables, or parameters  Declaring the datatype for a local variable in a batch or procedure

Chapter 1: System and User-Defined Datatypes

Declaring the datatype for a column in a table

To declare the datatype of a new column in a create table or alter table statement, use:

create table [[database.]owner.]table_name 
		(column_name datatype [identity | not null | null]
			[, column_name datatype [identity | not null |
				null]]...)
alter table [[database.]owner.]table_name 
		add column_name datatype [identity | null 
		[, column_name datatype [identity | null]... 

For example:

create table sales_daily
    (stor_id char(4)not null,
     ord_num numeric(10,0)identity,
     ord_amt money null)

You can also declare the datatype of a new column in a select into statement, use convert or cast:

select convert(double precision, x), cast ( int, y) into 
    newtable from oldtable




Copyright © 2005. Sybase Inc. All rights reserved. Declaring the datatype for a local variable in a batch or procedure

View this book as PDF