Access SQL Statement create tables always creates a field full of length - ms-access

I create a table with the following SQL using oledbconnection or immediately in access (installed version Office 365 MSO 32-bit and ACE 2016 32-bit):
CREATE TABLE Ticket (
[ID] COUNTER
, [Kundennummer] CHAR(15)
, [DC] CHAR(5)
, [Auftragsnummer] CHAR(25)
, [OZ] CHAR(5)
, [ASS] CHAR(20)
, [ASB] CHAR(5)
, [SPATZ] CHAR(19)
, [Status_num] INTEGER
, [Status_text] CHAR(255)
, [Bearbeitet_timestamp] DATE
, [IMPORT_ZEITSTEMPEL] DATE
, [RESULT_ZEITSTEMPEL] DATE
, CONSTRAINT [PrimaryKey] PRIMARY KEY ([ID])
);
The created table with "create table" always has the full restricted length for all fields with restricted length.
When I add a record in Access or via oleDbConnection, every field is padded to its full length with spaces.
How can I write the Create Table SQL in such a way that the table is created in such a way that only the actual field content is accepted. Or is there a setting in Access?
A table created with Access does not show this behavior.
Please help,
thank you

Use a VARCHAR field for a character field of varying length.
CHAR is fixed length so always needs to be fully filled, and pads with spaces if it isn't. While the GUI in Access doesn't support creating them, Access handles them just fine and just like most RDBMSes would.

Related

MySQL and phMyAdmin

I'm new to this website and using Mysql and phpMyAdmin. I need help with one of my table and I would really appreciate it. So, I created a table that has an Integer column I want to be able to limit it to only 7(Seven) digits I'm not quiet sure if this is possible using Mysql or phpMyAdmin.
I haven't tried any query on it. I want to limit the Integer type to only 7(Seven) digits.
This might not be the best possible solution but I think that if you were to store the integer as string in the format char(7) to limit the number of characters able to be entered it would get the job done.
I'm not familiar with Mysql in particular but here's some documentation on it : https://dev.mysql.com/doc/refman/8.0/en/char.html
I hope this helped.
In MySQL <8.0.16 You can't restrict the number of digits for an Integer. That has no meaning.
You can, however, use a DECIMAL type that allows you to specify the number of digits and the number of decimal places.
For example, DECIMAL(7,0) will define what you want.
Your CREATE statement becomes something like
CREATE TABLE IF NOT EXISTS myTable (
id INT AUTO_INCREMENT PRIMARY KEY,
someText VARCHAR(255) NOT NULL,
decimalValue DECIMAL(7,0)
) ;
If you're using MySQL 8.0.16 or later you can use a CHECK constraint to limit the value (as distinct from limiting the number of digits).
The example above becomes
CREATE TABLE IF NOT EXISTS myTable (
id INT AUTO_INCREMENT PRIMARY KEY,
someText VARCHAR(255) NOT NULL,
decimalValue INT,
CONSTRAINT `decValue_chk` CHECK (`decimalValue` <= 9999999))
) ;

SQL syntax error: two different platforms report different error

I am trying to make two database table and linked them together. Here is my code:
CREATE TABLE `NYSE_daily_prices_A` (
`StockSymbol` varchar(10) NOT NULL ,
`StockName` varchar(100) NOT NULL ,
`StockExchange` varchar(10) NOT NULL ,
PRIMARY KEY (
`StockSymbol`
)
);
CREATE TABLE `NYSE_stock_names` (
`StockExchange` varchar(10) NOT NULL ,
`StockSymbol` varchar(10) NOT NULL ,
`date` varchar(10) NOT NULL ,
`StockPriceOpen` money NOT NULL ,
`StockPriceHigh` money NOT NULL ,
`StockPriceLow` money NOT NULL ,
`StockPriceClose` money NOT NULL ,
`StockVolume` int NOT NULL ,
`StockPriceAdjClose` money NOT NULL
);
ALTER TABLE `NYSE_stock_names` ADD
CONSTRAINT `fk_NYSE_stock_names_StockSymbol`
FOREIGN KEY(`StockSymbol`)
REFERENCES `NYSE_daily_prices_A` (`StockSymbol`);
I tried to run this script in SQLiteStudio, it reports an error as following:
However, i copied the script into SQL Fiddle and it reports as following:
It really confuses me. How to fix this issue? Thanks in advance.
From SQLite's ALTER TABLE:
The ALTER TABLE command in SQLite allows these alterations of an
existing table: it can be renamed; a column can be added to it; or a
column can be dropped from it.
This means that with SQLite you can't add a foreign key constraint to an existing table.
Also, there are no varchar or money data types (they are interpreted as TEXT and NUMERIC affinities respectively), but this is not the source of the error.
In Mysql there is no money data type.
You can read this thread for an alternative: Best data type to store money values in MySQL
Your code, if you remove the backticks, is valid in SQL Server and Postgresql but not in MySql and SQLite.

Converting SQL Server code to MySQL

I am trying to concatenate two integers as the default value in a third field. My create table in SQL Server works fine:
CREATE TABLE MEI_Tbl
(
MEI_ID int PRIMARY KEY IDENTITY (1,1),
SRC tinyint NOT NULL DEFAULT '2',
HEI_ID AS (Cast (SRC as varchar)+ Cast (MEI_ID as varchar))
);
but when I try to create it in MySQL, I cannot find the equivalent for the concatenation of the two integers (Line 5 HEI_ID...).
**
I am aware of changing IDENTITY (1,1) to AUTO_INCREMENT for MySQL.
**
I have also tried several concat methods, but to no avail.
MySQL seems happier if I define the datatype for HEI_ID, and I have done so as varchar and int but again no success.
I have spent too much time reading about tool kits to convert SQL Server to MySQL. I just want to create the table in MySQL.
Any input would be appreciated.
MySQL does not support computed columns. Instead, you can use a view:
CREATE TABLE MEI_Tbl (
MEI_ID int PRIMARY KEY AUTO_INCREMENT,
SRC tinyint NOT NULL DEFAULT 2
);
CREATE VIEW v_MEI_Tbl as
SELECT MEI_ID, SRC,
CONCAT(src, mei_d) as HEI_ID
FROM MEI_Tbl
);
Then query from the view.

Prevent duplicate values in a calculated field on ms-access

I am really new to access. I have a calculated field(Name) in my Table which consist of 3 short text fields (fName + mName + lName).
I want to prevent any duplication in the calculated field (Name).
You can simply create a key using all three columns e.g.
CREATE TABLE myTable
(
fName VARCHAR( 25 ) NOT NULL,
mName VARCHAR( 25 ) NOT NULL,
lName VARCHAR( 25 ) NOT NULL,
UNIQUE ( lName, fName, mName )
);
Note the order of the columns in the key may be important if it will form the clustered index for the table (i.e. how it is physically stored on disk). Not sure whether this can be done using the MS Access user interface.
Store a calculated field isn't good idea (because you provide redundancy of data in the database). Can you calculate that value within real fields values on the fly on the form/query or other GUI?
To avoid duplicate data just create unique key/index for real fields

MYSQL > inserting steam id in int(11) with nosteam account that seems to long

A friend of mine is asking me for help, he has servers for steam games. He uses a mysql data base and has a plugin on his game that stocks STEAM ID (ID of a player in game)
I've tested the data out of the game (STEAM ID conversion from 64bit to 32bit) and compare it to what is inserted in the db... the results are not equal...
Strangely an ID "2150032574" become in mysql data field int(11) "-2144934722"
I have tested all the code PHP and SMX in the game to verify all datas... and according to me (but i am not sure) it would come from the SQL and the relation of the data (ID) lenght and not from the code.
Could it be possible that the length of the ID is too big (maybe because of the unsigned ID value?) and is converted i don t know how into that negative value ?
And what could i do to fix this problem ? I imagined to change int(11) into a varchar(128) for example... but that seems so so so brutal and abnormal for me...
Please could someone help ?
Cheers.
http://dev.mysql.com/doc/refman/5.7/en/integer-types.html
Signed INTs (the 11 does not relate to the max value the field can store) can store values up to 2147483647. UNSIGNED INTs can store values up to 4294967295. But since you wrote that you were getting a negative value after storing 2150032574, your field isn't UNSIGNED and so, can only store values up to 2147483647.
Assuming you don't have primary or foreign key constraints on your field, you could ALTER it to make it UNSIGNED, like so: ALTER TABLE steamids MODIFY COLUMN steamid INT(11) UNSIGNED;.
Ok the problem is solved by simply change the structure of the field authId from int() to bigint()
ALTER TABLE DBTABLE CHANGE FIELD FIELD BIGINT( 255 ) NOT NULL