Changed column name to upper case when create a new table through script in Oracle how to resolve this? - database

I am using Oracle tool (Oracle SQL Developer - Version 19.2.1.247).
When i create new table in Oracle Db then it change all column name in uppercase i.e.(CUSTOMERID), but i want to keep column name i.e.(CustomerId).I am looking for solutions how to resolve this.
I did some try to change formatting of editor as well code setting in Tools -> Preference but not found any proper things.
Thanks in advance.

You should avoid doing that. Every object ( table, column, index, sequence, trigger... ) is stored in uppercase in the Oracle dictionary.
However, if you want to store the name in lowercase, you must use double quotation
SQL> create table test ( c1 number );
Table created
SQL> select column_name from all_tab_columns where table_name = 'TEST';
COLUMN_NAME
C1
SQL> create table test ( "c1" number );
Table created
SQL> select column_name from all_tab_columns where table_name = 'TEST';
COLUMN_NAME
c1
Keep in mind that if you store the value in lowercase, any search or program that uses the dictionary will have to take this in consideration. That is why I believe it is not a good practice.

Oracle has a default functionality where it will convert all unquoted table/column identifiers to upper case, therefore add double quotes around the names should resolve your issue.

Related

Temporary tables in hana

it it possible to write script in hana that crate temporary table that is based
on existing table (with no need to define columns and columns types hard coded ):
create local temporary table #mytemp (id integer, name varchar(20));
create temporary table with the same columns definitions and contain the
same data ? if so ..i ill be glad to get some examples
i am searching the internet for 2 days and i couldn't find anything useful
thanks
Creating local temporary tables based on dynamic structure definition is not supported in SQLScript.
The question would be: for what do you want to use it?
Instead of a local temp. table you can use a table variable in most cases.
By querying sys.table_columns view, you can get the list and properties of source table and build a dynamic CREATE script then Execute to create the table.
You can find SQL codes for a sample case at Create Table Dynamically on HANA Database
For table columns read
select * from sys.table_columns where table_name = 'TABLENAME';
Seems to work in the hana version I have. I'm not sure how to find out what the version.
PROCEDURE "xxx.yyy.zzz::MY_TEST"(
OUT "OUT_COL" NVARCHAR(200)
)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
create LOCAL TEMPORARY TABLE #LOCALTEMPTABLE
as
(
SELECT distinct 'Cola' as out_col
FROM "SYNONYMS1"
);
select * from #LOCALTEMPTABLE ;
DROP TABLE #LOCALTEMPTABLE;
END
The newer HANA version (HANA 2 SPS 04 Patch 5 ( Build 4.4.17 )) supports your request:
create local temporary table #tempTableName' like "tableTypeName";
This should inherit the data types and all exact values from whatever query is in the parenthesis:
CREATE LOCAL COLUMN TEMPORARY TABLE #mytemp AS (
SELECT
"COLUMN1",
"COLUMN2",
"COLUMN3"
FROM MyTable
);
-- Now you can add the rest of your query here as such:
SELECT * FROM #mytemp
I suppose you can just write :
create column table #MyTempTable as ( select * from MySourceTable);
BR,

In SQL Server what's the difference between selecting a column as Year and [Year]?

Do we add '[]' just to differentiate the system defined keyword from our own ... ? Or is there any other reason behind using '[]'? Thanks!
The use of square brackets in t-sql is to allow you to use reserved words as object names or aliases.
However, I would recommend not using reserved words to begin with.
Here is my prefered method of avoiding the use of reserved words.
say you want to name your table my table only way to do this is to put it like so: [my table] . Same principle applies for other database objects.
create table [my table] (
column1 varchar(30), column2 varchar(50))

SQL server : Inserting/updating missing data from one table to another

I have two table "Container" and "Control". These are existing tables and there is no foreign key relationship between the two. These are also very old tables so are not normalized. And I cannot change the structure now.
Below is the structure of the two tables.
Container table :
Control Table :
The Name field in Control table contains CTableName+CPName from Container table.
I want to update the columnName field of Control table with the value of CID column of Container table. and also want to insert one more record (for ctable2 i.e the fourth row in final Control table below) in Control table.
The tablename and columnname columns have will always be have default values.
The final Control table should look like this:
How do I do this?
I hope you want to apply this fix because you want normalize your table structure.
Try this:
First step:
In this way you'll UPDATE all Control rows with the value of Container table where the couple fields CTableName and CPName are the same of Name (excluding the rows of Container with the same couple fields)
UPDATE Control
SET ColumnValue = (
SELECT c.CID
FROM Container c
WHERE c.CTableName + '+' + c.CPName = Control.Name
AND NOT EXISTS(
SELECT 'PREVIOUS'
FROM Container c2
WHERE c.CTableName = c2.CTableName
AND c.CPName = c2.CPName
AND c.CID < c2.CID
)
),
TableName = 'default', ColumnName = 'default'
WHERE ColumnValue IS NULL
Second step:
Adding elements don't present in Control table
INSERT INTO Control (field list)
SELECT field list
FROM Container co
WHERE NOT EXISTS(
SELECT 'in_control'
FROM Control ct
WHERE co.CID = ct.ColumnValue
)
After these two steps you can drop column Name in Control table
I am an Oracle plsql programmer and worked with Sql-server as well.
First you should describe the relationship between the 2 tables, in the end i could figger it out but it's better you explain it yourself.
To update a table with information from another table you should ask yourself:
- when should the update take place?
- what are the conditions to start the update?
- how should the update be done?
In Oracle there is a database object called a trigger. It's quite a handy object and probably just what you need. I believe that sql-server has it too.
Pls fee free to ask any questions but do read the sql-server appropriate manual as well.
Good luck, Edward.

What does master..sysdatabases and test..sysobjects mean?

I am learning how to use SQL server recently. I do not understand why use master..sysdatabases and test..sysobjects in the following statements:
select name from [master]..[sysdatabases] where dbid=1;
select count(1) from [test]..[sysobjects] where xtype = 'U';
What does the 1 in count(1) mean? Does it mean the first column?
Thanks for any helpful answers.
Your first line basically gets the name of the master database (it looks at the list of all databases, and returns the name of the database with the ID of 1, which in this case is generally going to be 'master').
Do a to see all the databases on a server:
SELECT * FROM [master]..[sysdatabases]
Note that the row with "dbid" = 1, is the row for the "master" database, which is a system database present on all SQL Server instances.
Your second line counts the number of rows in the sysobjects collection in the database named 'test' where the type is a user table (i.e. not a stored procedure, not a system table, etc).
In the expression "[x]..[y]", the 'x' is the name of the database, and 'y' is the name of the table or view within that database.
If you had a database named "Foo", and in there was a table named "Bar", then this statement would return the count of rows in that table:
SELECT COUNT(1) FROM [Foo]..[Bar]
As Ed Gibbs above described, the '1' is just a place-holder for counting the total number of rows in the most efficient way possible on any possible database or version. It's become a sort of short-hand way of counting.

Derby Database Table Column Name Format Inconsistent in Query

When query a Derby database, I find out that for some tables I have to double quote the column name and use table name to qualify the column name, but for some other tables I don’t need to. What happens to these tables and how can I make all tables the same and can query them without the double quote and the table name qualifier? I am using NetBeans IDE’s Sql Command tool. Below are those different queries.
Set schema app;
Select * from table1 where table1.”state” = ‘CA’;
Select * from table2 where state = ‘CA’;
Putting a tablename or column name in quotes, sometimes referred to by the jargon-y term "delimited identifiers" does two things:
Allows you to use words that are otherwise reserved keywords (e.g., naming a column "WHERE" or "SELECT")
Instructs the database system to process the name using case sensitive rules, rather than case-insensitive rules
So if you originally created "table3" with a CREATE TABLE statement that specified "table3" in double quotes like this, then you will forever after have to refer to it with the name in double quotes.
select * from table3
will be automatically processed by the database as if it was
select * from TABLE3
while
select * from "table3"
will successfully match the table you created as create table "table3"
See: http://db.apache.org/derby/docs/10.9/ref/crefsqlj34834.html

Resources