Abhii
Abhii

Reputation: 295

Creating table with column name (having spaces in between)

I want to create a table in which the column names have spaces.

like

create table IDE_Dump(
    Name varchar(255),
    Head Name varchar(255),
    Parent Account varchar (255)
);

The problem is to import bulk data from excel sheet to SQL Server 2008, whose headers are having the columns with spaces.

I have already tried ' ' or ` but its not working.

Upvotes: 12

Views: 33441

Answers (1)

You need to add [] brackets to column name.

CREATE TABLE IDE_Dump
(
   Name VARCHAR(255),
   [Head Name] VARCHAR(255),
   [Parent Account] VARCHAR(255) 
);

Or you can use double quotes "" as jarlh commented:

CREATE TABLE IDE_Dump
(
   Name VARCHAR(255),
   "Head Name" VARCHAR(255),
   "Parent Account" VARCHAR(255) 
);

Upvotes: 21

Related Questions