can not create join index in teradata database - teradata

i want to create a single table join index in teradata database,
here is the code i use:
create join index emp_ji as
sel
employee_number,
department_number,
last_name,
manager_employee_number
from customerservice.employee
primary index(last_name);
But i get the following errors:
I use user DBC, which should have all access,

Related

Can i save the output of a joined table into another table?

I created a database and having two tables like x and y. I cross joined them both and got an output.Now my question is can i save that output to a new table in the same database or different?
First you can try running the query SELECT * FROM table1 CROSS JOIN table2. Observe what columns are returned from the query, then create a new table new_table with columns of the appropriate type. Then you can try using INSERT INTO ... SELECT:
INSERT INTO new_table
SELECT * FROM table1 CROSS JOIN table2;
The CREATE TABLE statement directly accepts a query:
CREATE TABLE new_table AS
SELECT * FROM table1 CROSS JOIN table2;
(This will not keep the column types.)
The output can be saved in a different database if that database has been ATTACHed.

Move data to production tables after Bulk Insert to stage table

I have a database normalized like the one on the picture bellow. I store the clients, the accounts and the postal address for each account. As you can notice, the Client-Account relationship type is many-to-many, there for the ClientAccount table.
Since I have a database with 100k Account records I'm considering the use of SQL Bulk Copy. I think that I could use a stage table with all the fields of the tables above, and then normalize the data.
My problem is that I don't know how to move the data to the production tables. How can I create a stored procedure to perform this job, after the bulk insert import?
PS: The database is for as ASP .Net Web Site with the EF enabled.
You must insert one table at a time in the right order
Address -> Account -> Client -> AccountClient
create the addresses:
Insert into Address(data)
Select distinct address_data From temp
Account
Inser Into Account(account_number, address_id)
Select t.account_number, a.id From temp t
Inner Join Address a on a.data = t.address_data
Client
Insert into Client(name, client_number)
Select distinctname, client_number From temp
Client Account
Inser Into ClientAccount(accountId, clientId)
Select a.accountId, c.clientId From temp t
Inner Join Client c on c.name = t.name and c.client_number = t.client_number
Inner Join Account a on a.account_number= t.account_number
Make sure:
you don't create duplicate if some of the data are already there
you match on rows between real and temp table on the right columns

Same attributes, different tables in one database in SQLite

I am just new in SQLite and I have this assignment in creating database schema using the said program.
I just want to ask if it is allowed to give a same attributes present in different tables inside a single database. Let me give the SQLite statements of two tables in one database.
BEGIN TRANSACTION;
/* Create a table called Employee */
CREATE TABLE Employee(Name text, Phone_number varchar);
/* Create a table called Company */
CREATE TABLE Company(Name text, Country text);
I am referring to attribute Name which appears twice in two tables. Will it affect or distorts some of the SQL queries execution in the database?
If you had tried it (in the command-line shell or on SQLFiddle), you would have found out that it is allowed.
However, it can affect your queries.
When you join these two tables, you have to explicitly specifiy which table's column you want:
CREATE TABLE Employee(ID, CompanyID, Name, Phone_number);
CREATE TABLE Company(ID, Name, Country);
SELECT Company.Name,
Employee.Name,
Phone_number
FROM Company
JOIN Employee ON Company.ID = Employee.CompanyID;
On the other hand, if you have a foreign key relationship, using the same name in both tables allows you to simplify the join condition:
CREATE TABLE Employee(EmployeeID, CompanyID, Name, Phone_number);
CREATE TABLE Company(CompanyID, Name, Country);
SELECT Company.Name,
Employee.Name,
Phone_number
FROM Company
JOIN Employee USING (CompanyID);

Deleting rows from two tables using inner join SQLITE

How do you delete a row from two separate tables? I thought it would be possible to do this using an inner join
DELETE a.*, b.* FROM Holiday INNER JOIN Accommodation b on a.LocationID = b.LocationID
Here i try to delete by matching the primary key location in the first table to the location id in the second table. I get an SQL Exception "sqlException near a"
Im doing this in SQLITE, java
In SQLite, one DELETE command deletes from only one table.
Your query, as written, doesn't actually restrict the records to be deleted, so if you really want to delete all records, you would use this:
DELETE FROM Holiday;
DELETE FROM Accommodation;
If you want to delete one record in the master table and all corresponding records in the child table, you just filter by that key value:
DELETE FROM Holiday WHERE LocationID = 1;
DELETE FROM Accommodation WHERE LocationID = 1;

create table with constraints from another table in sqlite?

I want create table from another table with constraint?
I used this query "create table destination as select * from source;" fro table creation.
But its copy only the column name in table without column constraint.
There is a special table named sqlite_master, holding the full CREATE TABLE statement for each table (it's modified as appropriate during ALTER TABLE).
I would make my application retrieve that CREATE TABLE statement:
SELECT sql FROM sqlite_master WHERE type='table' AND name='source';
Then I would replace the table name right after CREATE TABLE tokens, and execute the result as a new sqlite query.
I don't think that it's possible to do in sqlite's pure SQL without extensions.

Resources