is there any special script to insert into Oracle cluster table - oracle11g

How to insert into oracle cluster tables and how to validate data inserted into that two tables correctly or not?
if I have two tables amp and dept.
these two table is cluster table and share same data blocks.
can I insert data into both table by simple insert statement.

can I insert data into both table by simple insert statement.
Yes, using INSERT ALL, such as
insert all
into emp (empno, ename) values (1, 'Little')
into emp (empno, ename) values (2, 'Foot')
--
into dept (deptno, dname) values (100, 'IT')
select * from dual;

Related

Sqllite search column name in db

I have a db in sqllite and it has almost 140 tables and many columns. And I don't know which table contain what column I have a specific requirement to search for specific column name
.
For example I have a database called msg. And it has almost 100 tables after lots of try I am unable to find exact column name like I am searching for localid in db from all table. I am using Sqllitestudio to see the db.
My question is can I search for just a column name and in which table or in how many tables that particular column exist.
Start the sqlite commandline tool.
Ask the "table of tables" about anything mentioning " localid " in the creation statement.
create table toy1 (thisid int, aletter char(1), anotherint int);
create table toy2 (globalid int, aletter char(1), localid int);
select * from sqlite_master where sql like '% localid %';
Output (with .headers on, in SQLite 3.18.0):
type name tbl_name rootpage sql
---------- ---------- ---------- ---------- --------------------------------------------------------------
table toy2 toy2 3 CREATE TABLE toy2 (globalid int, aletter char(1), localid int)
Edit the "where" clause to make the filter tighter or more generous, depending on what you need.

sqlite column constraint not in set of values

In sqlite, how do I restrict the values of a column to being not in another table/view column?
For example
sqlite> create table tab1(col1 check (col1 not in (1,2)));
does what I want except that it seems only to exclude hard-coded values. However, the following does not work -
sqlite> create table tab2(vals_to_exclude);
sqlite> insert into tab2 values(1);
sqlite> insert into tab2 values(2);
sqlite> create table tab3(col1 check (col1 not in (select vals_to_exclude from tab2)));
Error: subqueries prohibited in CHECK constraints
Is it possible to constrain a column to exclude a dynamically determined set of values?
If the built-in mechanisms are not sufficient, implement the check manually with a trigger:
CREATE TRIGGER tab3_col1_not_in_tab2
BEFORE INSERT ON tab3 -- you also need a trigger for UPDATEs
FOR EACH ROW
WHEN EXISTS (SELECT 1
FROM tab2
WHERE vals_to_exclude = NEW.col1)
BEGIN
SELECT RAISE(FAIL, "col1 conflicts with tab2");
END;
or, alternatively:
CREATE TRIGGER tab3_col1_not_in_tab2
BEFORE INSERT ON tab3 -- you also need a trigger for UPDATEs
FOR EACH ROW
BEGIN
SELECT RAISE(FAIL, "col1 conflicts with tab2")
FROM tab2
WHERE vals_to_exclude = NEW.col1;
END;

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.

Can column constraints be altered after creation in SQLite?

Say I have created a table like this:
CREATE TABLE table_1(column_1 UNIQUE, column_2 NOT NULL);
Now after I have inserted lots of data, for some reason I need to remove UNIQUE constraint from the first column, that's column_1. Is it possible? If yes, how?
ALTER TABLE in sqlite is very limited.
You can however, to a limited extent, change some contraints using CREATE INDEX and CREATE TRIGGER.
You could, eg:
CREATE TABLE table_1(column_1, column_2);
-- No constrains in table_1
CREATE UNIQUE INDEX t1_c1_1 ON table_1 (column_1);
-- From now, column_1 must be UNIQUE
CREATE TRIGGER t1_c2_1i BEFORE INSERT ON table_1 WHEN column_2 IS NULL BEGIN
SELECT RAISE(ABORT, 'column_2 can not be NULL');
END;
CREATE TRIGGER t1_c2_1u BEFORE UPDATE ON table_1 WHEN column_2 IS NULL BEGIN
SELECT RAISE(ABORT, 'column_2 can not be NULL');
END;
-- From now, NULL column_2 update/insert will fail
DROP TRIGGER t1_c1_1;
-- Now column_1 doesn't need to be UNIQUE
DROP TRIGGER t1_c2_1i;
DROP TRIGGER t1_c2_1u;
-- Now column_2 may be NULL
Note:
you can't delete existing constrains;
creating indexes will grow your data (index data);
creating trigger may degrade table performance.
Another workaround is duplicating existing table removing constraints:
CREATE TEMP TABLE table_1 AS SELECT * FROM MAIN.table_1;
DROP TABLE table_1;
CREATE TABLE table_1 AS SELECT * FROM TEMP.table1;
-- table_1 is now a copy from initial table_1, but without constraints
SQLite's ALTER TABLE statement does not support this.
Your best bet is to export the database as text (.dump in the sqlite3 tool), remove the UNIQUE constrant, and recreate the database.

Using temporary tables for update in stored procedure mysql

Can any one depict a simple example for using temporary tables in stored procedure for updating two tables in mysql?
Two kind of temporary tables available. One is session based and the other one is global temporary table.
Below is the simple example:
Select A,b,c into #MyTemp From MyDbTable
In the above example, #myTemp is the temporary table that you are creating. MyDbTable is the one that exist in your database. You can create multiple temporary tables.
I would suggest reading the article from here: Link
--Create a temp table and insert all these counts in it
Create Table #OperatorReportCount(Id int identity,Particulars varchar(100),NoOfArticles int)
--Insert these values in table
Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles processed',#ProcessedArticleCount)
Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles approved',#ArticlesApproved)
Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles rejected',#ArticleRejectedCount)
Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Rejections recieved',#RejectionsRecievedCount)
Insert Into #OperatorReportCount(Particulars,NoOfArticles) Values('Articles put on hold',#ArticlesOnHoldCount)
--Select the operator count table
Select Particulars,NoOfArticles From #OperatorReportCount

Resources