I see every day a lot of DDL statemente where i work, and i have seen that the people use to us,.Binary Multiples , but when i ask why, nobody tell me a real reason.
i mean
Create Table User(
User_name Varchar2(64 Byte),
User_comment (256 Byte),
User_Description (1024 Byte)
)
I see so often these values and i dont know why , if there is a logic behind that.
Related
I'm currently learning some basic stuff about sql in school. We received an exercise in which consists in creating a script that creates tables. We have a schema and we need to recreate it.
I'm having some issues with this one:
When I run the script, it shows this error:
CREATE TABLE "EMPLOYEE" ( "BIRTH_DATE" DATE , "FIRST_NAME" VARCHAR(14) , "LAST_NAME" VARCHAR(16) , "GENDER" ENUM('M','F') , "HIRE_DATE" DATE ) IN "TS_EMPLOYEE"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "(" was found following "16) , "GENDER" ENUM".
Expected tokens may include: "DEFAULT". SQLSTATE=42601
I looked for the error on the internet and thought I should specify the DEFAULT. For this reason I modified the script adding this part:
"GENDER" ENUM('M','F')DEFAULT 'M' ,
Unfortunately it didn't help me much, since it indicates me the same mistake as before.
Does anyone know where I am wrong? Or what I could change?
Any kind of help is appreciated! ^^
I don't think DB2 supports enums. If you are using DB2, then use a check constraint:
CREATE TABLE EMPLOYEE (
BIRTH_DATE DATE,
FIRST_NAME VARCHAR(14),
LAST_NAME VARCHAR(16),
GENDER CHAR(1),
HIRE_DATE DATE,
CHECK (GENDER IN ('M', 'F'))
);
Notes:
I removed the double quotes. Just don't use them for identifiers. They only clutter queries and introduce the possibilities for strange errors.
I think such a table should have a primary key, although I have not added one.
The lengths of the strings for the names seems unnecessarily short.
I am looking for help with a query to do the following:
Before the insert of a row, find how many rows in 2 tables have the same information as is being inserted.
So basically I am looking to see if this row will be a complete duplicate.
I want to base this on all the columns, not just the PK, because if there is even one column different then this is a valid insert.
This is something along the lines of what I need, although incorrect:
SELECT COUNT(*)
FROM ORDER_TRF_HEADER
WHERE
((SELECT * FROM ORDER_TRF_HEADER_COMPLETE WHERE MA_PONUM = '29608207') = (SELECT * FROM ORDER_TRF_HEADER WHERE MA_PONUM = '29608207'));
Table - ORDER_TRF_HEADER
MA_CUST VARCHAR2(8 BYTE)
MA_PONUM VARCHAR2(30 BYTE)
MA_ODATE VARCHAR2(8 BYTE)
MA_ITEMS NUMBER(3,0)
MA_SALEM VARCHAR2(2 BYTE)
MA_PDAYS NUMBER(3,0)
MA_CURR VARCHAR2(3 BYTE)
Table - ORDER_TRF_HEADER_COMPLETE
MA_CUST VARCHAR2(8 BYTE)
MA_PONUM VARCHAR2(30 BYTE)
MA_ODATE VARCHAR2(8 BYTE)
MA_ITEMS NUMBER(3,0)
MA_SALEM VARCHAR2(2 BYTE)
MA_PDAYS NUMBER(3,0)
MA_CURR VARCHAR2(3 BYTE)
Thanks
I want to base this on all the columns, not just the PK, because if there is even one column different then this is a valid insert.
then your issue is that you have NOT defined your primary key correctly.
Certainly there are good reasons for not maintaining a primary key consisting of every attribute in the record, however a better solution than checking for duplicates in such a clumsy way before inserting would be to maintain a has of the data as a unique key.
You can try INTERSECT.
SELECT COUNT(*)
FROM (SELECT *
FROM order_trf_header_complete
WHERE ma_ponum = '29608207'
INTERSECT
SELECT *
FROM order_trf_header
WHERE ma_ponum = '29608207') ;
Note:: You better use all column names explicitly instead of select *
I am creating multiple tables in MS SQL SERVER 2014 to that will receive data from an Oracle server. Some of the data types that are coming over from Oracle are set to VARCHAR2 (15 BYTE), VARCHAR2(60 BYTE) ETC....
I need to know what I should set my data types too in the MS SQL SERVER tables.
ITEM_NO VARCHAR(15 BYTE)
UNIT_OF_MEASURE CHAR(2 BYTE)
PARTNER_SKU VARCHAR(15 BYTE)
UPC CHAR(12 BYTE)
ITEM_DESC VARCHAR(60 BYTE)
ALT_ITEM_NO VARCHAR(15 BYTE)
As previously stated in the comments above by #Gordon Linoff and #user2067753 in SQL Server you do not need to define the word BYTE when specifying data types in SQL Server. So for your declared fields above:
ITEM_NO VARCHAR(15)
UNIT_OF_MEASURE CHAR(2)
PARTNER_SKU VARCHAR(15)
UPC CHAR(12)
ITEM_DESC VARCHAR(60)
ALT_ITEM_NO VARCHAR(15)
MSDN has many articles which you might also find helpful:
Data Types
Creating Tables
You also might find these documents quite useful as it compares both Microsoft SQL Server to Oracle and documents a load of the differences:
From Oracle
On MSDN
Byte in Oracle is optional, Just used to enforce the size to be specific number of bytes rather than the length of the varchar value. There is no equivalent in SQL Server
I'm trying to export an existing Oracle SQL database schema so that I can use it to build up an Apache Derby database.
Whenever I use the "Database Export" functionality of SQL Developer 4.0.1.14, it generates the sql files, but they are in a format that Apache Derby cannot work with.
Does anybody know of any way to export the schema so that that format is compatible with Apache Derby?
Examples:
Apache Derby wants something like this:
CREATE TABLE "SURVEY"."LOAD_BALANCE"
( "LOAD_BALANCE_ID" NUMBER,
"SURVEY_ID" NUMBER,
"ROUTING_SERVICES" VARCHAR(255),
"ALGORITHM" VARCHAR(255),
"WEIGHT" VARCHAR(255),
"STICKINESS" VARCHAR(255),
"HEALTH_MONITOR" VARCHAR(255),
"SSL_USED" VARCHAR(255)
)
But SQL Developer outputs it like this:
CREATE TABLE "SURVEY"."LOAD_BALANCE"
( "LOAD_BALANCE_ID" NUMBER,
"SURVEY_ID" NUMBER,
"ROUTING_SERVICES" VARCHAR2(255 BYTE),
"ALGORITHM" VARCHAR2(255 BYTE),
"WEIGHT" VARCHAR2(255 BYTE),
"STICKINESS" VARCHAR2(255 BYTE),
"HEALTH_MONITOR" VARCHAR2(255 BYTE),
"SSL_USED" VARCHAR2(255 BYTE)
)
You might try DdlUtils: http://db.apache.org/ddlutils/
I know it supports Derby, and the project website says it supports Oracle, so ...
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.