Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating table with column name (having spaces in between)

Tags:

sql

sql-server

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.

like image 939
Abhii Avatar asked Apr 09 '15 11:04

Abhii


People also ask

How do I create a SQL table with spaces in a column name?

DML SQL query with space in a column name When we run INSERT, UPDATE, and DELETE statements, we must use a square bracket or double quotes to handle the column name with space.

Can column names have spaces?

Column names can contain any valid characters (for example, spaces).

Can table names have spaces in SQL?

Table names can contain any valid characters (for example, spaces).

How do I remove blank spaces in SQL column?

SQL Server TRIM() Function The TRIM() function removes the space character OR other specified characters from the start or end of a string. By default, the TRIM() function removes leading and trailing spaces from a string. Note: Also look at the LTRIM() and RTRIM() functions.


1 Answers

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) 
);
like image 198
Stanislovas Kalašnikovas Avatar answered Oct 06 '22 17:10

Stanislovas Kalašnikovas