1

I have table in my database with next SQL code

CREATE TABLE `table` (
`id` INTEGER  PRIMARY KEY AUTO_INCREMENT NOT NULL,
`column1` VARCHAR(255) NOT NULL,
`column2` INTEGER  NULL,
`column3` INTEGER  NULL,
`column4` INTEGER  NULL,
`default` INTEGER  NULL
);

And i can insert data into it with

INSERT INTO `table` VALUES (1,'something',1,0,0,1)

and it works, but my question is how to enter specific values with problem that i have column with name default and SQL interprets that name of column like default value. Therefore i can't use inserts like

INSERT INTO `table` (id,column1,column2,column3,column4,default) VALUES (1,'something',1,0,0,1),

or

INSERT INTO `table` (id,column1,default) VALUES (1,'something',1),

or etc.

So my question is : Is it possible to insert specific data into table with column name default and how or not? Is it possible to work this on some other databases? I'm using MySql database.

Thanks in advance

3
  • 1
    That's a really bad column name. (And table is a really bad table name.) "defualt" is the ANSI SQL way, MySQL may use back-ticks. Commented Sep 3, 2015 at 8:28
  • 1
    @jarlh Well I wasn't the designer of the database, and i never use that kind of names for column names. I'm only trying to figure out the proper way to insert data into that kind of table. Commented Sep 3, 2015 at 8:35
  • Having inherited databases before... I feel your pain! Commented Sep 3, 2015 at 8:48

5 Answers 5

1

Try escaping the column name default with backticks, like you have with the table name.

Sign up to request clarification or add additional context in comments.

Comments

1

do the same thing that you did on your table:

INSERT INTO `table` (`id`,`column1`,`default`) VALUES (1,'something',1),

Comments

1

Replace

default

with

`default`

Comments

0

You can use the following command and it will allow you to insert the value in the default column:

INSERT INTO `table` (id,column1,column2,column3,column4,`default`) VALUES (2,'something',1,0,0,1);

Use the same quotes over default as used for table by you.

Comments

0

for SQL, Back Ticks ( ` ) are not accepted in SSMS, square brackets [] are very commonly used in the automatic selections. try putting the column names in square brackets. [DEFAULT]. INSERT INTO [MyTableName] ([id],[column1],[column2],[column3],[column4],[default]) VALUES (1,'something',1,0,0,1);

1 Comment

The question is tagged mysql and your answer seems to be about SQL Server so I don't know how that will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.