Sql syntax error - expecting ( or as - sql

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
)

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
);

I am creating a table in pgweb Heroku, and get this error "ERROR: pq: syntax error at or near "(""

Here is my exact query
CREATE Table Publisher
(Publisher_Id Int primary key not null,
Name varchar(20) not null,
Address varchar(50) not null,
Phone Int(10),
Isbn varchar(13) references books (Isbn) not null
)
Any help would be greatly appreciated.
datatype int does not take a length. So:
create table publisher (
publisher_id int primary key,
name varchar(20) not null,
address varchar(50) not null,
phone int,
isbn varchar(13) references books (isbn) not null
);
Notes:
not null is redondant on a primary key column
int does not seem like a good pick for a phone number; you would typically need to store leading 0s, or allow special characters such as + or () - int cannot do that. A string datatype would probably be a better pick

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.

what does the error "missing right parenthesis" in oracle sql means

I'm trying to run this code and it seems correct to me but I'm getting an error stating that there's a right parenthesis missing.
The code is the following:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID INT NOT NULL,
NAME VARCHAR(30) NOT NULL,
DATE_OF_BIRTH DATE,
PHONE_NB CHAR(8) NOT NULL,
ADDRESS VARCHAR(50),
TOTAL_SPENDING FLOAT NOT NULL DEFAULT 0.0,
PRIMARY KEY(CUSTOMER_ID)
);
Can anyone help me in solving my problem?
Since you tagged SQL Developer...
...the tool tries to give you a heads-up there will be a problem before you even hit the Execute button
The default value for the column is confusing the parser because it's not expected at that point.
Move it to after the data type and you'll be good
CREATE TABLE customer (
customer_id INT NOT NULL,
name VARCHAR2(30) NOT NULL,
date_of_birth DATE,
phone_nb CHAR(8) NOT NULL,
address VARCHAR(50),
total_spending FLOAT DEFAULT 0.0 NOT NULL,
PRIMARY KEY ( customer_id )
);
PS In oracle, use VARCHAR2, not VARCHAR. While VARCHAR will 'work', it's reserved and could mean something different in a future release.
You are using wrong order of column definition clauses: the constraint (NOT NULL) should follow the default value.
This is the right way:
CREATE TABLE CUSTOMER
(
CUSTOMER_ID INT NOT NULL,
NAME VARCHAR(30) NOT NULL,
DATE_OF_BIRTH DATE,
PHONE_NB CHAR(8) NOT NULL,
ADDRESS VARCHAR(50),
TOTAL_SPENDING FLOAT DEFAULT 0.0 NOT NULL ,
PRIMARY KEY(CUSTOMER_ID)
);

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

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