Creating a users table in SQL - sql

I'm trying to create a Users table:
CREATE TABLE users
( user_id int(5) PRIMARY KEY,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL
);
But I keep getting this error:
Error starting at line 1 in command:
CREATE TABLE users ( user_id int(5) PRIMARY KEY, username varchar(25) NOT NULL, password varchar(30) NOT NULL )
Error at Command Line:2 Column:13
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Any ideas?

don't try to put precision for integer type:
CREATE TABLE users
( user_id int PRIMARY KEY,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL
);

Looks like it's related to your int(5) data type specification. See Oracle numerica data types.
Try something like:
CREATE TABLE users
( user_id NUMBER PRIMARY KEY,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL
);

try
CREATE TABLE users
( user_id int PRIMARY KEY,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL
);

The following works, but note that the PRIMARY KEY constraint is added at the end of the command
CREATE TABLE users(
user_id int NOT NULL,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL,
PRIMARY KEY(user_id)
);

To create a table:
CREATE TABLE users
( user_id int(5) NOT NULL,
username varchar(25) NOT NULL,
password varchar(30) NOT NULL,
PRIMARY KEY(user_id)
);

Related

"Syntax error in constraint clause" MS Access creating a table

I keep getting the syntax error in access when trying to add a foreign key to a table. The foreign key is LendorID and it is referenced in another table. What am I doing wrong?
Here is my code for creating the table:
CREATE TABLE BOOK_INVENTORY
(
CRN int NOT NULL PRIMARY KEY,
AuthorLastName varchar(20) NOT NULL,
AuthorFirstName varchar(20) NOT NULL,
BookTitle varchar (100) NOT NULL,
LendorID varchar(5) FOREIGN KEY REFERENCES LENDOR_INFO(LendorID),
);
Here is my code for the table that contains LendorID:
CREATE TABLE LENDOR_INFO
(
LendorID varchar(5) NOT NULL,
LendorLastName varchar(20) NOT NULL,
LendorFirstName varchar(20) NOT NULL,
LendorEmail varchar(100) NOT NULL,
PRIMARY KEY (LendorID)
);

How to create table in oracle?

** I've created table in oracle but getting following error:
ORA-00903: invalid table name
**
CREATE TABLE user
(id INT NOTNULL AUTO_INCREMENT,
name VARCHAR(45) NOTNULL,
email VARCHAR(45) NOTNULL,
password VARCHAR(45) NOTNULL,
PRIMARY KEY(id));
A few things to correct here
USER is reserved
NOTNULL
primary definition
autoincrment
varchar2 is preferred over varchar
but you'll end up with something like
SQL> CREATE TABLE users
2 (id INT generated as identity NOT NULL ,
3 name VARCHAR2(45) NOT NULL,
4 email VARCHAR2(45) NOT NULL,
5 password VARCHAR2(45) NOT NULL,
6 constraint users_pk PRIMARY KEY(id)
7 );
Table created.
Also checkout quicksql.oracle.com which lets you type in metadata and it generates the table definitions for you. A great way to get started

postgresql table fails to create

create table users (
id VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL,
password VARCHAR(50) NOT NULL,
);
gokitexample=# \i /Users/henryhudson/OneDrive/Henry/Programming/Go/go-kit/account/users.sql
psql:/Users/henryhudson/OneDrive/Henry/Programming/Go/go-kit/account/users.sql:5:
ERROR: syntax error at or near ")"
LINE 5: );
The error is quite explicit. There is an additional comma at the end of the last column. It should be like that:
create table users (
id VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL,
password VARCHAR(50) NOT NULL
);

How to debug the error in this SQL command?

I am trying to execute this SQL command to create a table.
CRETE TABLE NEWS (
ID INT(128) NOT NULL AUTO_INCREMENT,
TITLE VARCHAR(128),NOT NULL,
SLUG VARCHAR(128) NOT NULL,
TEXTS_S TEXT NOT NULL,
PRIMARY (ID), );
)
You need:
Create table news (
ID INT(128) NOT NULL AUTO_INCREMENT,
TITLE VARCHAR(128) NOT NULL,
SLUG VARCHAR(128) NOT NULL,
TEXTS_S TEXT NOT NULL,
PRIMARY KEY (ID) );
Missing KEY at the end, bogus comma on the line creating TITLE, another bogus comma on the PRIMARY line. First problem was the full stop in the table name.
Create table news
(
ID INT identity (1,1) primary key ,
TITLE VARCHAR(128) NOT NULL,
SLUG VARCHAR(128) NOT NULL,
TEXTS_S TEXT 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!