Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

mysql - Coverting script for older SQL version to work with 5.6

Apologies if my fundamental understanding of the issue is incorrect. I am not very experienced with SQL and am still learning.

I am attempting to generate a table for a data set and was given this script:

CREATE TABLE [dbo].[lobbying](
[uniqid] [varchar](36) NOT NULL, [registrant_raw] [varchar](110) NULL, [registrant] [varchar](50) NULL, [isfirm] [char](1) NULL,
[client_raw] [varchar](110) NULL, [client] [varchar](50) NULL,
[ultorg] [varchar](50) NULL,
[amount] [float] NULL,
[catcode] [char](5) NULL,
[source] [char] (5) NULL,
[self] [char](1) NULL,
[IncludeNSFS] [char](1) NULL,
[use] [char](1) NULL,
[ind] [char](1) NULL,
[year] [char](4) NULL,
[type] [char](4) NULL,
[typelong] [varchar](50) NULL, [affiliate] [char](1) NULL,
) ON [PRIMARY]

As you can probably tell, it doesn't work. The script was updated in 2015 so that is why I presume the issue to be the version. I tried using SQL Fiddle to figure out what was causing the issue, and found that taking the brackets out helped(which makes sense, as the tutorial I was following did not use any brackets for their tables). However, even with that, I still receive the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use char(1) NULL,
ind char(1) NULL,
year char(4) NULL,
type char(4) NULL,
typelo' at line 10

Does anybody know what the issue is here? Any help would be greatly appreciated. I've poured out about 4 hours into this project so far and have not been able to get past this roadblock.

question from:https://stackoverflow.com/questions/65865748/coverting-script-for-older-sql-version-to-work-with-5-6

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is enough to replace the names with brackets with backticks and also remove the brackets around the type nqames

CREATE TABLE lobbying(
`niqid`varchar(36) NOT NULL
, `egistrant_raw`varchar(110) NULL
, `egistrant` varchar(50) NULL
, `isfirm` char(1) NULL,
`client_raw` varchar(110) NULL
, `client` varchar(50) NULL,
`ultorg`  varchar(50) NULL,
`amount` float NULL,
`catcode` char(5) NULL,
`source` char(5) NULL,
`self` char(1) NULL,
`IncludeNSFS` char(1) NULL,
`use` char(1) NULL,
`ind` char(1) NULL,
`year` char(4) NULL,
`type` char(4) NULL,
`typelong`  varchar(50) NULL
, `affiliate` char(1) NULL
) 
?

db<>fiddle here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...