How to rename column in Big Query? [closed] - google-bigquery

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
We are loading Datastore tables(i.e. kinds)(taken as backup in cloud storage) into Big Query manually. Is there any way to transform(rename etc.) datastore columns before being loaded to Big Query. It seems to support feature of E(extraction) and L(loading) but not T(transform) when datastore kind backups are loaded in Big Query.
The problem is that we have column-key as a primary field in our datastore kinds and hence we see column with name- "_key__.id" when kind loaded into Big Query.
We wanted this column to be loaded with name 'id' not "_key__.id". So just wondering, is there any way to rename the column in Big Query?
Timely help is hightly appreciated.

The "T" part of ETL is supported by means of SQL querying. You could either use directly query datastore backup as external table (https://cloud.google.com/bigquery/external-data-sources) or first load into temp table and then run SQL to transform it.
Renaming in Standard SQL will look like following:
SELECT * EXCEPT(oldname1, oldname2), oldname1 as newname1, oldname2 as newname2 FROM ...
But since you mentioned name separated by dot: _key__.id it is probably nested field with _key__ being of type RECORD, so the SQL will look like
SELECT * EXCEPT(_key__), _key__.id AS id FROM ...

Related

SQL Server - CROSS DEPENDENCIES DATABASES [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm able to pull cross databases dependencies but when the referencedDB is DIFFERENT DATABASE then I'm able to fetch the referenced object but not referenced OBJECT TYPE (e.g user_table,stored procedure etc..,)
Is there any way to find the OBJECT TYPE of referencedDB object?
Thanks in advance.
The system views (e.g., sys.object) are views, effectively under the schema sys.
So you should be able to get object types etc from statements like
SELECT type_desc
FROM yourOtherDatabaseName.sys.Objects
WHERE name = 'yourObjectToCheck'
Note - Information_schema is also similar - you can use them like
SELECT TOP 10 * from
yourOtherDatabaseName.INFORMATION_SCHEMA.tables

SQL naming convention: Adding data type to column name [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
As a developer, a common mistake that I keep on repeating is assuming the data type of a column. I have read multiple articles regarding SQL column naming convention but have not seen any reference regarding data type as part of the column name - specifically for SQL Server.
E.g. Revenue_f for float, Organization_v for varchar, AccountNumber_i for integer and so on.
This must have been thought of already before but I want to know the reason why it is not being used, or an expert's input regarding the matter; pointing me to the right article/documentations will be greatly appreciated.
That is a horrible naming convention. Consider how awful it would be if you need to change AccountNumber to a character datatype. Do you then go back and rename the column and change every single query everywhere? Or do you leave the suffix in your column name even though it is no longer accurate? If you want to know the datatype of a column the ONLY way is to look at the definition of the table.
Also, a single character really is kind of useless. How do you handle nvarchar vs varchar? And what about the scale?
P.S. Even though I wrote an answer I am voting to close this question because it is primarily opinion based and as such is considered off topic for SO.

Database table columns names [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have noticed that some people in database columns instead of for example id, user, addressare using something like h_id, e_user, f_address etc...
Is that some kind of security aspect? or maybe these are some shortcuts of words?
Its because there might be many id fields like user_id,category_id,that's why they use so that code is understandable.
And talking about columns name like f_address, they are just shortcut for say first address. It doesn't have anything to do with security but to increase the query readability use proper name to fields so that people can understand just by seeing column name what data it saves.
If there are fields like category_id and sub_category_id , it is understandable from the field name, but if i denote it using c_id and s_id, its hard to depict.
Well, 'User' is a security object in SQL Server, so using that is kind of scary. 'ID' and 'address' are way too generic to provide any semantics when used as attribute names.
If a purpose of design is to be maintainable and readable, then there some words that simply don't work.
Definitely not security related.
Some use it for readability or speed (you don't have to remember which table you gave a certain name->see following example) when writing queries.
i.e.
select a.name, b.name from table1 a join table2 b on a.id=b.id
Like this you have to remember that table1 is named a and table2 is named b etc.
But if you use tablename_field (which you can shorten by using only the first letter of the tablename). That way you never have duplicate fieldnames when creating join queries.

How to check if one table is replica of other table in SQL? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to find if one table is replica of other table in SQL
In SQL Server, you can compare the results of:
SELECT checksum_agg(checksum(*))
FROM Table1;
SELECT checksum_agg(checksum(*))
FROM Table2;
You could create a join with these as sub-queries if you want, too.
You may wish to use binary_checksum() instead of checksum(). The doc says that checksum() will treat strings that are equal as equal according to the collation (i.e., 'hello' and 'HELLO' if the collation is case-insensitive), while binary_checksum() compares the raw binary values of characters.
This works for MySQL:
CHECKSUM TABLE table_1, table_2;

Display endless amount of data in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If I have an endless amount of data, can I display all of it in sql?
I know there is obviously select *, but then it will never complete.
Is there a command for this?
You can use TOP to select subset of total records
SELECT TOP 100 * from table
This selects top 100 records.
By using Order By clause , you can specify the basis on which subset of records is returned.
Now if you are asking about limits of Sql Server database management system then please see this link - Maximum Capacity Specification of Sql Server
Eg
Max Databases per instance of SQL Server ( both 32 bit and 64 bit ) = 32,767
Usually, you will prefer to use some kind of paging, since you cannot actually show "endless amount of data" in user-friendly way on application.