How to deal with temp tables when compiling database project - visual-studio-2010

We just created a solution with multiple data projects. We inherited the system and want to do a database cleanup but when we compile some of the databases we get the error that table, id etc does not exist and it occures where temp tables are created in stored procedures.
Let's say a stored proc creates a temp table and at the end drops it the compiler complains and says that the table does not exist (in the database schema). How can we work around this? Any settings I can't find?
Thanks in advance.

There is a bug filed in Microsoft Connect on this issue, and there is a workaround suggested: use table variables instead of temporary tables. So, use
declare #t table (ID int, Name nvarchar(100) )
insert into #t ...
instead of
create table #t (ID int, Name nvarchar(100) )
insert into #t ...
drop table #t

Related

Impossible to create trigger in a table with a reserved name in Oracle

I have a table named BLOB, and I can select, update, insert normally via SQL, but it's impossible to define a trigger for it, obviously the cause is the name.
In PL/SQL as a procedure, I work around the problem by creating a view which selects all the columns of the table, and using it in the body but it doesn't work on the table itself.
Does anyone have a solution? I cannot rename the table. Also using a synonym is out.
Structure of the table:
CREATE TABLE BLOB
(
BLOBID CHAR(7 BYTE) NOT NULL,
OGGETTO BLOB
)
The problem is related to the presence of a column of type BLOB in a table named BLOB, but only in PL/SQL environment (procs, triggers, ...)

Creating instances of global temporary table

I created a GTT at schema level
CREATE GLOBAL TEMPORARY TABLE schema1.gtt1
(
col1 type1,
col2 type2,
...
)
ON COMMIT PRESERVE ROWS;
Now I can reference the table from within a PLSQL block/procedure/function very easily:
INSERT INTO schema1.gtt1
select col1, col2, ... from ...;
but what if in the same PLSQL block I want to insert values in another global temporary table (GTT) with the same structure as the one I created?
Do I have to create another GTT, and give it another name even if it has the very same structure (I think it would be awkward)? or can I somehow create multiple instances of a GTT?
Don't know if it's relevant but I'll be joining the GTT's with other tables, within the same PLSQL block.
You have 2 tables, A and B with same structure. (GTT but accessed from same session so we can ignore this)
Your question do I have to insert in both at runtime or can I use only one?
This is a question that only you can answer based on the meaning of what you insert and your need to differentiate the records.
If you need to make the difference between these 2 record sets (what you insert in A and what in B) but you have no key to make this distinction than you would need to: add a new column in structure like "source" or insert into different tables.
There is no "multiple instances" concept of GTT within session so this won't do the trick.

How to Recover an Entire Oracle Schema

I was using Navicat for Oracle to backup an entire Schema. I mistakenly selected the Execute SQL File instead of the Backup file option and All previous data has been changed/lost. I tried using the Oracle Undo feature but it says the table definition has changed. Please i am not skilled in oracle, i only used it for a project cause it was required so i just use it to store the data. I need all the help i can get right now to recover the entire schema to how it was 24 hours ago else i am so screwed...(forgive my language)
From your description you ran a script that dropped and recreated your tables. As you have flashback enabled and your dropped table is in the recycle bin, you can use the 'Flashback Drop' feature to get the dropped table back.
Here's an example with a single table:
create table t43 (id number);
drop table t43;
create table t43 (id2 number);
show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
-------------------------------- ------------------------------ ------------------------- -------------------
T43 BIN$/ILKmnS4b+jgQwEAAH9jKA==$0 TABLE 2014-06-23:15:38:06
If you try to restore the table with the new one still there you get an error:
flashback table t43 to before drop;
SQL Error: ORA-38312: original name is used by an existing object
You can either rename the restored table:
flashback table t43 to before drop rename to t43_restored;
... which is useful if you want to keep your new table but be able to refer to the old one; or probably more usefully in your situation rename the new table before restoring:
alter table t43 rename to t43_new;
table T43 altered.
flashback table t43 to before drop;
table T43 succeeded.
desc t43
Name Null Type
---- ---- ------
ID NUMBER
You can undrop all of your tables, and as referential constraints still work with tables in the bin you don't have to worry too much about restoring parent tables before child tables, though it's probably neater to do that if you can.
Note that the bit in the documentation about retoring dependent objects - that index names won't be preserved and you'll need to rename them after the restore with alter index.
You can't undrop a sequence; those don't go into the recycle bin. If you need to reset a sequence so it doesn't repeat values you already have, you can get the highest value it should hold (from the primary keys on your restored table, say) and use temporarily change the increment value to skip over the used numbers.

Moving dependencies (PK, FK and indexes) from one table to another within the same database in Oracle

Please tell me how can I move dependencies (such as PK, FK and indexes) from one table to another within the same database in Oracle? The second table is a copy of the first, only created later for partition reasons. Thank you in advance! :)
You could look at using the dictionary views in oracle, specifically the USER_CONSTRAINTS view. Then either construct a SQL statement dynamically or use DBMS_METADATA.get_ddl procedure to get the ddl for the constraint. You could do a REPLACE on the SQL to replace the original table name and constraint name with a new constraint name and the name of the new table.

Temporary table in Oracle like SQL Server

In SQL Server one could do something like the following
declare #t as table(id int)
insert into #t values(1)
insert into #t values(2)
delete from #t where id=1
Is there an equivalence of this in Oracle without creating a physical table. Now, I used to create physical table to do this and delete later.
I have gone to this links How to create a temporary table in Oracle but that's 2010 and the reference link mentioned Oracle 8i. Is this still the situation with Oracle 10g and 11g? Another link I have visited is Constructing a temporary table in Oracle SQL
Thanks
CREATE GLOBAL TEMPORARY TABLE admin_work_area
(startdate DATE,
enddate DATE,
class CHAR(20))
ON COMMIT DELETE ROWS;
This statement creates a temporary table that is transaction specific.
For details use below link:
http://docs.oracle.com/cd/B28359_01/server.111/b28310/tables003.htm#i1006400
In most cases you do not need it. In Oracle when you need temporary table then "your design is wrong". Do not try to rewrite MS SQL pattern into Oracle which exact wording. Where you use temporary table in MS SQL you use in Oracle CTE(nested subquery, query factoring) a CURSOR or some PL/SQL construct.
The temporary table is not what you need. It's just a tool you use to achieve some goal. In Oracle you should use other tools.
Use an Associative Array :)
declare
type temp_rec is record(v integer);
type temp_table is table of temp_rev indexed by pls_integer;
my_temp_table temp_table;
begin
-- Here you can do do your stuff :)
end
/

Resources