Saturday, September 3, 2011

How to create column names with blank space as a separator in Sybase ASE?

Usually when we try to create a table with some given set of column names we are not able to use blank in between the column name so if we have to create a column say - Employee Name then we create it like EmpName or EmployeeName with no space. What if we require to have the same column name as - "Employee Name" or "Emp Name"? What to do in such a case?

Well, if we will try to create the column name using the simple method then we will hit on the column name error very early as soon as we try to create the table structure or add one using alter table command. So we will try to use similar approach with a slight tweak so as to tell the Adaptiver Server that we want to name the column specifically as what we are suggesting in the command so please let us do the same. A normal create table command to create an Employee table will be as follows -

create table Employee
(
  EmpId int,
  EmployeeName varchar(100),
  EmpAge int,
  EmpSalary float,
  DeptId int
)
go

However, to get create the table with a blank space in between we will write the same syntax as -

create table Employee
(
   [Emp Id] int,
   [Employee Name] varchar(100),
   [Emp Age] int,
   [Emp Salary] float,
   [Dept Id] int
)
go

and we are done with it.

No comments:

Post a Comment