There was an error parsing the query. [ Token line number = 2,Token line offset = 3,Token in error = Employee_ID ] - sql

I am trying to execute the below query but iam getting the folowing error.
Create table Employee(
Employee_ID char(5)Primary key,
First_Name char(20) NOT NULL,
Last_Name char(20) NOT NULL,
Phone_Number varchar(20) NULL
);
Major Error 0x80040E14, Minor Error 26302
> Create table Employee(
Employee_ID char(5)Primary key,
First_Name char(20) NOT NULL,
Last_Name char(20) NOT NULL,
Phone_Number varchar(20) NULL
)
The specified data type is not valid. [ Data type (if known) = char ]

If the database you are using is some version of Microsoft SQL Server Compact Edition (which the error message would suggest) the error stems from the fact that particular database doesn't support thechar/varchardata types as it's purely unicode based. What you need to do is to use the corresponding unicode data typesnchar/nvarcharlike this:
Create table Employee (
Employee_ID nchar(5) Primary key,
First_Name nchar(20) NOT NULL,
Last_Name nchar(20) NOT NULL,
Phone_Number nvarchar(20) NULL
);
For reference: Data Types Supported in SQL Server CE

Related

Alternative to Postgresql BIGSERIAL data type in Azure Database?

I am learning Azure and data analytics with Azure. Recently finished learning Postgresql.
My question is if there is an alternative to BIGSERIAL data type for Azure Databases. I ran the query (below the error in the following) and had an error. Note that this datatype exists in Postgresql and hence I am getting confused in Azure. Any alternative to BIGSERIAL?
Failed to execute the query. Error: Column, parameter, or variable #1:
Cannot find data type BIGSERIAL.
create table person (
ID BIGSERIAL NOT NULL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(50),
gender VARCHAR(50) NOT NULL,
date_of_birth DATE NOT NULL,
Country_of_birth VARCHAR(50) NOT NULL
);
In PostgreSQL, the SERIAL keyword is used to setup an auto increment column, this works similar to auto increment in SQL. BIGSERIAL is an auto-incremented Bigint column of 8 bytes.
Closest, I could find "bigserial"in MS docs is as here
So...you can use BIGINT instead, below works fins for me.
create table person (
ID BIGINT NOT NULL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(50),
gender VARCHAR(50) NOT NULL,
date_of_birth DATE NOT NULL,
Country_of_birth VARCHAR(50) NOT NULL
);

Issue with SQL create table error in Microsoft SQL Server

Can someone help me find the reason this SQL query isn't working in Microsoft SQL Server?
CREATE TABLE USER
(
USER_ID int NOT NULL PRIMARY KEY,
USER_L_NAME varchar(30) NOT NULL,
USER_F_NAME varchar(20) NOT NULL,
PASSWORD varchar(20) NOT NULL,
USERNAME varchar(20) NOT NULL,
DOB date NOT NULL,
COUNTRY char(30) NOT NULL,
STATE_REGION char(2),
EMAIL varchar(20) NOT NULL,
STREET varchar(50) NOT NULL,
CITY varchar(30),
ZIP_CODE char(5),
MOBILE_PHONE char(11)
);
USER is a reserved word in SQL Server - as in most other databases.
You can either quote this identifier by surrounding it with square brackets (CREATE TABLE [USER] (...)), or change the table name to something else - such as USERS for example.
I would recommend the latter. Using reserved words for identifiers is error-prone (you need to quote the identifier everywhere you use it later on), and can easily be avoided.

ORACLE SQL - invalid data type on table creation

I am trying to set up a table in an ORACLE database and am getting an invalid data type error when I try to run this command:
CREATE TABLE Students (
StudentID NUMBER(8) NOT NULL,
FirstName VARCHAR(25) NOT NULL,
Surname VARCHAR(25) NOT NULL,
Address VARCHAR(100) NOT NULL,
Postcode VARCHAR(7) NOT NULL,
DoB DATE NOT NULL,
Gender VARCHAR(1) NOT NULL,
StudentCategory VARCHAR(50),
StudyType VARCHAR(20),
Nationality VARCHAR(20),
SmokerStatus BOOLEAN,
SpecialNeeds VARCHAR(30),
Comments VARCHAR(30),
PlacedStatus BOOLEAN,
CourseID NUMBER(6) NOT NULL,
AdvisorOfStudies NUMBER(6) NOT NULL,
NextOfKin NUMBER(8) NOT NULL
);
According to the error message, something is occuring 'starting on line 1'. That would mean on the actual create statement itself, rather than any of the data dictionary. I don't understand how this can be causing the invalid data type error.
If anyone can spot what might be causing this, that'd be greatly appreciated!
Error Details:
Error report -
SQL Error: ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Thanks,
Mark
Change SmokerStatus from BOOLEAN to char(1). Oracle does not have boolean data type . You need to use char(1) or number(1) for this purpose.
SmokerStatus char(1),

Sql syntax error - expecting ( or as

I am trying to write this SQL code:
create table Users
{
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
Email not null
}
The problem is that next the { symbol, I get the error:
Incorrect syntax near '{'.
When my mouse over the sign it adds:
Expecting '(' or AS
In addition, I also get an error on the values that are in the bracket
Incorrect syntax near '20'. Expecting '(' or Select".
The thing is that I have another SQL document (that I didn't write) and the same syntax work there! Why is that and how can I solve it?
You need brackets not braces - http://www.w3schools.com/sql/sql_create_table.asp Also a data type for email
I.e.
create table Users
(
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
Email varchar(40) not null
)
You have not specified the datatype for Email columnn.
Use ()instead of {}.
Your sql statement should look like the following one, first change the {} to () then added the datatype to your email column
create table Users (
UserID int primary key identity(200,1),
FirstName varchar(20) not null,
LastName varchar(20) not null,
BirthDate dateTime not null,
HomeTown varchar(30),
WorkPlace varchar(40),
[Email] varchar(255) not null
)

Error in my SQLite syntax

New to SQLite so I don't know what I'm doing wrong. I'm just getting an error saying:
SQLSTATE[HY000]: General error: 1 near "CREATE": syntax error
Here's my SQL:
CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY,
date_created DATETIME NOT NULL,
date_updated DATETIME NOT NULL,
username VARCHAR(32) NOT NULL,
password VARCHAR(32) NOT NULL,
role VARCHAR(32) NOT NULL DEFAULT 'member',
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(128) NOT NULL
)
CREATE TABLE subscribers (
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(40) DEFAULT NULL,
email VARCHAR(255) NOT NULL UNIQUE
)
CREATE TABLE weekly_download (
id INTEGER NOT NULL PRIMARY KEY,
filename TEXT NOT NULL,
download_date DATE NOT NULL,
body TEXT
)
put a semicolon after each statement.
CREATE TABLE ( ... ) ;
CREATE TABLE ( ... ) ;
Start with simple statements using the sqlite3 CLI.
Then, if you forget a ;, you will get quick feedback and can build up to more complex SQL.
$ sqlite3 /tmp/test.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> create table badsyntax;
SQL error: near ";": syntax error
sqlite> create table abc (x,y);
sqlite>
Don't forget semi-colons!