Teradata high volume table optimization - teradata

I have to optimize this table structure. This table has 43 million records and it will grow.
Any suggestions on creating the PPI n all. This table along with 5 similar tables are being used in a Business view.
CREATE MULTISET TABLE GEEDW_Q_PLP_S.CDR_ODS_INTER_DATE_398850F1 ,
NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
ID VARCHAR(128) TITLE 'ID' NOT NULL
,ROOT_INTERFACE_NAME VARCHAR(128) TITLE 'ROOT INTERFACE NAME'
,INTERFACE_NAME VARCHAR(512) TITLE 'INTERFACE NAME'
,ATTRIBUTE_NAME VARCHAR(512) TITLE 'ATTRIBUTE NAME'
,ATTRIBUTE_VALUE TIMESTAMP(0) TITLE 'ATTRIBUTE VALUE'
,CHECKSUMTEXT VARCHAR(40) TITLE 'CHECKSUMTEXT'
,DW_LOAD_DTTM TIMESTAMP(0) TITLE 'DW LOAD DTTM' NOT NULL
,DW_CREATED_BY VARCHAR(20) TITLE 'DW CREATED BY' NOT NULL
,DW_UPDATED_DTTM TIMESTAMP(0) TITLE 'DW UPDATED DTTM' NOT NULL
,DW_UPDATED_BY VARCHAR(20) TITLE 'DW UPDATED BY' NOT NULL)
PRIMARY INDEX CDR_ODS_INTER_DATE_398850F1_PI ( ID,ROOT_INTERFACE_NAME );

Related

Issue with importing Image into CLOB data using TPT script

I have a simple tpt script (given below) to load image into CLOB column in an empty table.
USING CHARACTER SET UTF8
DEFINE JOB LoadingtableData
DESCRIPTION 'Loading data into table using TPT'
(
DEFINE SCHEMA TableStaging
DESCRIPTION 'SYS FILE Staging Table'
(
Col_Colb CLOB(131072) AS DEFERRED BY NAME
,Col_FNAME VARCHAR(100)
,Col_ID VARCHAR(50)
);
DEFINE OPERATOR FileReader()
DESCRIPTION 'Read file with list'
TYPE DATACONNECTOR PRODUCER
SCHEMA TableStaging
ATTRIBUTES (
VARCHAR TraceLevel = 'None'
, VARCHAR PrivateLogName = 'read_log'
, VARCHAR FileName = 'datafile.txt'
, VARCHAR OpenMode = 'Read'
, VARCHAR Format = 'Delimited'
, VARCHAR TextDelimiter = ',');
DEFINE OPERATOR SQLInserter()
DESCRIPTION 'Insert from files into table'
TYPE INSERTER
INPUT SCHEMA TableStaging
ATTRIBUTES (
VARCHAR TraceLevel = 'None'
, VARCHAR PrivateLogName = '#LOG'
, VARCHAR TdpId = '#TdpId '
, VARCHAR UserName = '#UserName '
, VARCHAR UserPassword = '#UserPassword ');
STEP LoadData (
APPLY ('INSERT INTO table_A(Col_Colb,Col_FNAME,Col_ID) VALUES (:Col_Colb,:Col_FNAME,:Col_ID);')
TO OPERATOR (SQLInserter [1])SELECT * FROM OPERATOR (FileReader ());););
To load data into table I'm using two text files:
File have all the Varchar column values and Clob data location.
Example data in file: <Clob_File_Location>,Name,123
Clob column value
Example data in file: Image.png
After executing the above tpt, I get message as "data loaded successfully". But when I check the table in place of image in Clob column text is loaded.
Can someone help in letting me know what I might be doing wrong.

How to configure periods dynamically according to number of persons?

I'm making a database for my expense tracker/splitter (offers possibility to add/edit/remove Transactions). Depending on number of Persons, when you add a new transaction you must specify who paid and to what amount. Then it creates Payments row for each person within Transactions.
You must configure each person's salary then it will calculate the pro-rata for each person for unpaid expenses (IsPayed flag). Once every person is ready to settle they must create a period (start and end date). All transactions between those dates will be tagged as paid (IsPayed = true) and the application will assume they are settle and frozen in time. There will be a FK between Transaction and Period to specify from which period a transaction was paid.
I want to add a relation between Period(Id) and SalaryConfiguration(IdGroup); it would specify SalaryConfiguration for said period, but I can't since IdGroup is not a primary key. I do not know how a period can be dynamic on the number of persons and specific configurations. How can I link SalaryConfiguration and Periods?
Database DDL:
CREATE TABLE "Transactions" (
"Id" INTEGER NOT NULL UNIQUE,
"FkIdCategories" INTEGER NOT NULL,
"Date" TEXT NOT NULL,
"Name" TEXT NOT NULL,
"Description" TEXT,
"Cost" INTEGER NOT NULL,
"IsPayed" INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY("Id" AUTOINCREMENT),
CONSTRAINT "Fk_Categories_Transactions" FOREIGN KEY("FkIdCategories") REFERENCES "Categories"("Id")
);
CREATE TABLE "Categories" (
"Id" INTEGER NOT NULL UNIQUE,
"Name" TEXT NOT NULL UNIQUE,
PRIMARY KEY("Id" AUTOINCREMENT)
);
CREATE TABLE "Payments" (
"Id" INTEGER NOT NULL UNIQUE,
"FkIdPerson" INTEGER NOT NULL,
"FkIdTransaction" INTEGER NOT NULL,
"Amount" INTEGER NOT NULL,
CONSTRAINT "Fk_Persons_Payments" FOREIGN KEY("FkIdPerson") REFERENCES "Persons"("Id"),
CONSTRAINT "Fk_Transactions_Payments" FOREIGN KEY("FkIdTransaction") REFERENCES "Transactions"("Id"),
PRIMARY KEY("Id" AUTOINCREMENT)
);
CREATE TABLE "Persons" (
"Id" INTEGER NOT NULL UNIQUE,
"Name" TEXT NOT NULL,
PRIMARY KEY("Id" AUTOINCREMENT)
);
CREATE TABLE "SalaryConfigurations" (
"Id" INTEGER NOT NULL UNIQUE,
"IdGroup" INTEGER NOT NULL,
"FkIdPerson" INTEGER NOT NULL,
"Salary" INTEGER NOT NULL,
"SaveDate" TEXT NOT NULL,
CONSTRAINT "Fk_Persons_SalaryConfiguration" FOREIGN KEY("FkIdPerson") REFERENCES "Persons"("Id"),
PRIMARY KEY("Id" AUTOINCREMENT)
);
CREATE TABLE "Periods" (
"Id" INTEGER NOT NULL UNIQUE,
"StartDate" TEXT NOT NULL,
"EndDate" TEXT NOT NULL,
"FkIDSalaryConfigurationGroup" INTEGER NOT NULL,
PRIMARY KEY("Id" AUTOINCREMENT)
);
You can link the two tables together with another table that contains SalaryConfigurations(Id) and Periods(Id).

is it possible to fetch database DDL in teradata

i know we can use SHOW TABLE DATABASENAME.TABLENAME to get the DDL of a certain table in teradata,
like,
show table customerservice.employee;
result:
CREATE SET TABLE customerservice.employee ,FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
employee_number INTEGER,
manager_employee_number INTEGER,
department_number INTEGER,
job_code INTEGER,
last_name CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
first_name VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
hire_date DATE FORMAT 'YY/MM/DD' NOT NULL,
birthdate DATE FORMAT 'YY/MM/DD' NOT NULL,
salary_amount DECIMAL(10,2) NOT NULL)
UNIQUE PRIMARY INDEX ( employee_number );
If i want to show DDL of a certain database, is it possible ?

#1062 - Duplicate entry '1' for key 'PRIMARY'

I am importing database and i got an error
1062 - Duplicate entry '1' for key PRIMARY.
i tried to upload table individually But it gives me error for those table which have at least one row.
i don't want to delete any record of any table.
here is one table which is giving error.
CREATE TABLE IF NOT EXISTS `wpbeta_aff_affiliates` (
`affiliate_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`email` varchar(512) DEFAULT NULL,
`from_date` date NOT NULL,
`thru_date` date DEFAULT NULL,
`status` varchar(10) NOT NULL DEFAULT 'active',
`type` varchar(10) DEFAULT NULL,
PRIMARY KEY (`affiliate_id`),
KEY `affiliates_afts` (`affiliate_id`,`from_date`,`thru_date`,`status`),
KEY `affiliates_sft` (`status`,`from_date`,`thru_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `wpbeta_aff_affiliates`
--
INSERT INTO `wpbeta_aff_affiliates` (`affiliate_id`, `name`, `email`, `from_date`, `thru_date`, `status`, `type`) VALUES
(1, 'Direct', NULL, '2013-07-03', NULL, 'active', 'direct');
You do not need to specify the record id (with the exception of some circumstances when you need to keep the connection between records in different tables). Try using this query:
INSERT INTO wpbeta_aff_affiliates (name, email, from_date, thru_date, status, type) VALUES ('Direct', NULL, '2013-07-03', NULL, 'active', 'direct');

How to create ENUM type in SQLite?

I need to convert a table from MySQL to SQLite, but I can't figure out how to convert an enum field, because I can't find ENUM type in SQLite.
The aforementioned field is pType in the following table:
CREATE TABLE `prices` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`pName` VARCHAR(100) NOT NULL DEFAULT '',
`pType` ENUM('M','R','H') NOT NULL DEFAULT 'M',
`pField` VARCHAR(50) NULL DEFAULT NULL,
`pFieldExt` VARCHAR(50) NULL DEFAULT NULL,
`cmp_id` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
ENGINE=MyISAM
ROW_FORMAT=DEFAULT
I need a field with only three values for the user to chose, and I would like to enforce that in the DB, not just in my application.
SQLite way is to use a CHECK constraint.
Some examples:
CREATE TABLE prices (
id INTEGER PRIMARY KEY,
pName TEXT CHECK( LENGTH(pName) <= 100 ) NOT NULL DEFAULT '',
pType TEXT CHECK( pType IN ('M','R','H') ) NOT NULL DEFAULT 'M',
pField TEXT CHECK( LENGTH(pField) <= 50 ) NULL DEFAULT NULL,
pFieldExt TEXT CHECK( LENGTH(pFieldExt) <= 50 ) NULL DEFAULT NULL,
cmp_id INTEGER NOT NULL DEFAULT '0'
)
This will limit the pType column to just the values M, R, and H, just
like enum("M", "R", "H") would do in some other SQL engines.
There is no enum type in SQLite, only the following:
NULL
INTEGER
REAL
TEXT
BLOB
Source: http://www.sqlite.org/datatype3.html
I'm afraid a small, custom enum table will be required in your case.
To expand on MPelletier’s answer, you can create the tables like so:
CREATE TABLE Price (
PriceId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Name VARCHAR(100) NOT NULL,
Type CHAR(1) NOT NULL DEFAULT ('M') REFERENCES PriceType(Type)
);
CREATE TABLE PriceType (
Type CHAR(1) PRIMARY KEY NOT NULL,
Seq INTEGER
);
INSERT INTO PriceType(Type, Seq) VALUES ('M',1);
INSERT INTO PriceType(Type, Seq) VALUES ('R',2);
INSERT INTO PriceType(Type, Seq) VALUES ('H',3);
Now the enumeration values are available directly in the Price table as they would be using an ENUM: you don’t need to join to the PriceType table to get the Type values, you only need to use it if you want to determine the sequence of the ENUMs.
Foreign key constraints were introduced in SQLite version 3.6.19.

Resources