Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use LONG data type

I'm trying to get some legacy SQL 2005 code to work on SQL 2012 Express. However, whenever I set the compatibility_level to 90, I error out when I try to use older data types. In theory the following code should work:

USE wsus_results
GO

ALTER DATABASE wsus_results
SET compatibility_level = 90
GO

CREATE TABLE ScTable (
 TblName VARCHAR(255) NULL,
 TblType VARCHAR(255) NULL, 
 FieldCnt INTEGER NULL,
 RecordCnt LONG NULL,
 Description LONGVARCHAR NULL,
 TblId AUTOINCREMENT PRIMARY KEY)
GO

But, I get the following error:

Msg 2715, Level 16, State 6, Line 2 Column, parameter, or variable #4: Cannot find data type LONG.

I'm sure there's something simple I'm missing, and I just need a nudge in the right direction. This isn't a permission issue and as far as I can tell, the SET compatibility_level = 90 executes fine with no errors. Still, I get an error when using LONG.

like image 879
Chad Harrison Avatar asked Jul 30 '13 17:07

Chad Harrison


People also ask

How do you declare a long data type?

You can declare and initialize a Long variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. If the integer literal is outside the range of Long (that is, if it is less than Int64. MinValue or greater than Int64.

What is a long data type?

Long (long integer) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647. The type-declaration character for Long is the ampersand (&).

Can we use long in SQL?

LONG is not a valid data type in any version of SQL Server. And changing compatibility level will not affect your ability to use old or new data types.

IS LONG data type supported in Java?

The long data type is a 64-bit two's complement integer. Its value-range lies between -9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive). Its minimum value is - 9,223,372,036,854,775,808and maximum value is 9,223,372,036,854,775,807. Its default value is 0.


1 Answers

LONG is not a valid data type in any version of SQL Server. And changing compatibility level will not affect your ability to use old or new data types. This only affects the way certain language constructs are parsed.

Perhaps you meant DECIMAL or BIGINT.

And to pre-empt further questions: LONGVARCHAR and AUTOINCREMENT are not valid data types either (check the documentation instead of guessing). Where did you get this script, and who suggested it should work in SQL Server? I think you may have been pranked. Try this instead:

USE wsus_results;
GO

ALTER DATABASE wsus_results
SET compatibility_level = 110;
GO

CREATE TABLE dbo.ScTable -- schema prefix is important!
(
 TblName     VARCHAR(255),
 TblType     VARCHAR(255), 
 FieldCnt    INT,
 RecordCnt   BIGINT,
 Description VARCHAR(MAX),
 TblId       INT IDENTITY(1,1) NOT NULL PRIMARY KEY
);
GO

As an aside, is every other column in the table really nullable? Does your table name really need a suffix Table? What does Sc mean? Why not actually call the table what it represents (such as SocialCows or ScientificCholesterol) instead of obfuscating the name and adding a meaningless suffix just to incur more typing?

like image 193
Aaron Bertrand Avatar answered Sep 18 '22 07:09

Aaron Bertrand