Situation
My data is stored on a PostgreSQL server on my network. I've linked an ODBC data source to create linked tables to my data. The table in concern is one that is designed to track classes and their session details - including attendance. The table's design is so:
CREATE TABLE ClassSession
(
id integer NOT NULL DEFAULT nextval('"seq_ClassSession_id"'::regclass),
teacher_id integer NOT NULL,
class_name character varying(50) NOT NULL,
clients_in_attendance integer[],
date_of_session date DEFAULT CURRENT_DATE,
CONSTRAINT "ClassSession_pkey" PRIMARY KEY (id)
)
Problem
MS Access interprets integer[] data types as Short Text (pictured below). This isn't really a big deal as long as I can match the correct format of integer enclosed in { and } - with each being separated by a ,. An example would be: {12,34,56,67,78}.
Integer arrays as Short Text in Access - design view
Query example of Access interpreting integer arrays as short text/format
Question
I was looking for some direction on how to design a form in Access that can insert data into this table while restricted to this format (using the {, }, and , in plaintext) without having the user type the brackets, each number, and comma to separate the client_id values. Is anyone able to help?
Related
I need to be able to write a script to create a table in Microsoft Access, and I am running into a problem. I need a long integer field (longer than LONG), so I have to use DECIMAL. The problem I am running into is it is defaulting the Format to scientific notation. I need it to stay as a normal integer value.
Here is my script:
CREATE TABLE MY_TABLE
(
MY_GUID GUID CONSTRAINT MY_CONSTRAINT PRIMARY KEY,
MY_NAME VARCHAR,
CREATOR VARCHAR,
MILLI_CREATED DECIMAL (13, 0)
);
The MILLI_CREATED field defaults to General Number Format, which then displays the value in scientific notation, like this: 1.444255960009E+12
How can I set the Format of the table during CREATE or with an ALTER or even at INSERT if that is what I have to do?
I am fairly new to SQL but have been working hard to learn. I am currently stuck on an issue with setting a primary key to have 8 digits no matter what.
I tried using INT(8) but that didn't work. Also AUTO_INCREMENT doesn't work in PostgreSQL but I saw there were a couple of data types that auto increment but I still have the issue of the keys not being long enough.
Basically I want to have numbers represent User IDs, starting at 10000000 and moving up. 00000001 and up would work too, it doesn't matter to me.
I saw an answer that was close to this, but it didn't apply to PostgreSQL unfortunately.
Hopefully my question makes sense, if not I'll try to clarify.
My code (which I am using from a website to try and make my own forum for a practice project) is:
CREATE Table users (
user_id INT(8) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(30) NOT NULL,
user_pass VARCHAR(255) NOT NULL,
user_email VARCHAR(255) NOT NULL,
user_date DATETIME NOT NULL,
user_level INT(8) NOT NULL,
UNIQUE INDEX user_name_unique (user_name),
PRIMARY KEY (user_id)
) TYPE=INNODB;
It doesn't work in PostgreSQL (9.4 Windows x64 version). What do I do?
You are mixing two aspects:
the data type allowing certain values for your PK column
the format you chose for display
AUTO_INCREMENT is a non-standard concept of MySQL, SQL Server uses IDENTITY(1,1), etc.
Use a serial column in Postgres:
CREATE TABLE users (
user_id serial PRIMARY KEY
, ...
)
That's a pseudo-type implemented as integer data type with a column default drawing from an attached SEQUENCE. integer is easily big enough for your case (-2147483648 to +2147483647).
If you really need to enforce numbers with a maximum of 8 decimal digits, add a CHECK constraint:
CONSTRAINT id_max_8_digits CHECK (user_id BETWEEN 0 AND < 99999999)
To display the number in any fashion you desire - 0-padded to 8 digits, for your case, use to_char():
SELECT to_char(user_id, '00000000') AS user_id_8digit
FROM users;
That's very fast. Note that the output is text now, not integer.
SQL Fiddle.
A couple of other things are MySQL-specific in your code:
int(8): use int.
datetime: use timestamp.
TYPE=INNODB: just drop that.
You could make user_id a serial type column and set the seed of this sequence to 10000000.
Why?
int(8) in mysql doesn't actually only store 8 digits, it only displays 8 digits
Postgres supports check constraints. You could use something like this:
create table foo (
bar_id int primary key check ( 9999999 < bar_id and bar_id < 100000000 )
);
If this is for numbering important documents like invoices that shouldn't have gaps, then you shouldn't be using sequences / auto_increment
I am trying to create a SQL table in Netbeans 8.0 with one of its columns meant to store a byte[] (so VARBINARY is the type I am looking for). The wizard for the creation of a new table offers me the option of VARCHAR FOR BIT DATA, which should work, but it raises a syntax error when creating the table:
create table "BANK".Accounts
(
id NUMERIC not null,
pin VARCHAR FOR BIT DATA not null,
primary key(id)
)
The error is due to the presence of the word FOR, so I manually change the statement so that it is
create table "BANK".Accounts
(
id NUMERIC not null,
pin "VARCHAR FOR BIT DATA" not null,
primary key(id)
)
but now the problem is that the type does not exist. Any ideas?
Thank you.
Here's the manual page for VARCHAR FOR BIT DATA: http://db.apache.org/derby/docs/10.10/ref/rrefsqlj32714.html
Note the section that says:
Unlike the case for the CHAR FOR BIT DATA type, there is no default length for a VARCHAR FOR BIT DATA type. The maximum size of the length value is 32,672 bytes.
So the problem is that you haven't specified a length.
If your byte array is, say, 256 bytes long, you could specify
pin VARCHAR (256) FOR BIT DATA NOT NULL,
You might also consider using BLOB if that fits your requirements. You can see all the Derby data types here: http://db.apache.org/derby/docs/10.10/ref/crefsqlj31068.html
I am trying to create a table in Oracle SQL Developer but I am getting error ORA-00902.
Here is my schema for the table creation
CREATE TABLE APPOINTMENT(
Appointment NUMBER(8) NOT NULL,
PatientID NUMBER(8) NOT NULL,
DateOfVisit DATE NOT NULL,
PhysioName VARCHAR2(50) NOT NULL,
MassageOffered BOOLEAN NOT NULL, <-- the line giving the error -->
CONSTRAINT APPOINTMENT_PK PRIMARY KEY (Appointment)
);
What am I doing wrong?
Thanks in advance
Last I heard there were no boolean type in oracle. Use number(1) instead!
Oracle does not support the boolean data type at schema level, though it is supported in PL/SQL blocks. By schema level, I mean you cannot create table columns with type as boolean, nor nested table types of records with one of the columns as boolean. You have that freedom in PL/SQL though, where you can create a record type collection with a boolean column.
As a workaround I would suggest use CHAR(1 byte) type, as it will take just one byte to store your value, as opposed to two bytes for NUMBER format. Read more about data types and sizes here on Oracle Docs.
Oracle doesn't support boolean for table column datatype. You should probably use a CHAR(1) (Y/N)
You can see more info on this other answer
i think u got a below good result
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/datatypes.htm#CJACJGBG
When using an Entity class to create the schema, defining the boolean value as below will help
#Column(columnDefinition = "number default 0")
private boolean picked;
I am new to writing SQL and using Oracle... so I'm sorry if this is obvious but I can't figure it out. It's telling me that I'm missing a right parenthesis but as far as I can tell they are all there. It seems to be a problem with the VARBINARY line but I don't know why.
CREATE TABLE DATA_VALUE
(
DATA_ID VARCHAR2(40) NOT NULL,
POSITION INT NOT NULL,
VALUE VARCHAR2(50),
BINARY_VALUE VARBINARY(50),
DATA_TYPE VARCHAR2(20),
CONSTRAINT DATA_VALUE_PK PRIMARY KEY(DATA_ID, POSITION)
);
VARBINARY is not an Oracle data type. A quick search suggests MySQL and SQL Server have it, at least, but not Oracle. Perhaps you need to explain what you want to store in that field. The closest I can think you might mean is RAW.
The valid built-in datatypes are listed in the documentation:
The RAW and LONG RAW data types store data that is not to be
explicitly converted by Oracle Database when moving data between
different systems. These data types are intended for binary data or
byte strings.
This Microsoft article suggests you should be using RAW as a replacement for VARBINARY too, at least for the size you're talking about.
CREATE TABLE DATA_VALUE
(
DATA_ID VARCHAR2(40) NOT NULL,
POSITION INT NOT NULL,
VALUE VARCHAR2(50),
BINARY_VALUE RAW(50),
DATA_TYPE VARCHAR2(20),
CONSTRAINT DATA_VALUE_PK PRIMARY KEY(DATA_ID, POSITION)
);
table DATA_VALUE created.