User defined data types in T-sql - sqldatatypes

I had a look in the tables I am using in my database based on Rapid SQL. In one of the table i was just checking columns used in that table. I used sp_help table_name to find out the details of columns, datatypes and other things. I found some data types as T_gender_domain, T_name_domain, T_phone_domain. Are they used as a user defined data types???

Related

What do the various tables in Hive Metastore contain?

I went through the Hive Metastore database and found that it contains a lot of tables (for example TBLS, DBS, etc).
I want to know what data do these various tables store?
I tried to find some sort of documentation for the meaning of these individual tables, and their columns but couldn't find any.
There are many tables present in Hive metastore each one for a specific purpose. Hive uses this metastore to store its metadata (Database names, table names, columns, data types, etc.) For example, the TBLS table contains data related to Hive tables such as table name, table owner, created time, Database ID, etc.
These tables are related to each other with foreign keys and useful information can be retrieved by querying them with joins.
A sample query to find all the database names and their corresponding tables with column name and type is shown below.
SELECT DBS.NAME, TBLS.TBL_NAME, COLUMNS_V2.COLUMN_NAME, COLUMNS_V2.TYPE_NAME FROM TBLS, COLUMNS_V2, SDS, DBS WHERE TBLS.SD_ID=SDS.SD_ID AND COLUMNS_V2.CD_ID=SDS.CD_ID AND TBLS.DB_ID=DBS.DB_ID
ER diagram of the metastore - https://datacadamia.com/_media/db/hive/hive_metastore_er_diagram.png
Some useful queries can be found here - https://analyticsanvil.wordpress.com/2016/08/21/useful-queries-for-the-hive-metastore
I also didn't find any specific documentation on the same but I think this could help!!

Mapping a query with different column names (sometimes in a different language) to a table in a different server

What is the best tool or method to map a SQL Server query to a SQL Server table with different column names?
Secondly and separately, is there a tool that considers objects and values in a different language. I attempted to use Redgate; however, the SQL Compare function does not allow for mapping with different column names.
Mapping is needed for different queries from different agencies who each use different table/column names. In some cases, the language for the columns and values are different (i.e., Italian, Spanish).
SQL Data Compare (not SQL Compare) lets you compare a table against a view. So If you create a view on the second table, giving it the column names used in the first table, then you can use the Tables and Views tab to map the table with the view.
Make sure you "include views" in the Options tab to see the views listed in the tables and views tab.

SQL Direct Reference to Data

Is there a way in Microsoft SQL to reference a specific item of data based on table, column and record?
For example, table A (COL1 INT, COL2 INT) has 2 records (1,2) and (3,4). Can I somehow capture value 4 by reference, rather than as "4"?
The purpose is to allow me to create an audit method that can point to specific value in a (table, column, record) without having to duplicate that value in my audit table (which could be large, therefore bloating my database size).
I am thinking ... just like Object_Id identifies a particular SQL object, so would this reference (some kind of GUID, perhaps?) identify a specific piece of data.
Many thanks in advance.
The answer is No. In MS SQL (and, as far as I know in other popular databases) there are no such references to specific values.
Moreover, even table rows in MS SQL do not have embedded unique identifiers, unless you take care to create an IDENTITY column.
You can yourself make the implementation of such references. For example, create a table with columns
data_id,
table_name,
row_id,
column_name
and fill it up every time you need a reference. Then you can refer to piece of data by data_id.
But this is not a good solution.
in most cases, a single entry in this table will consume more space
than the referenced data value itself
to get the values ​​you still have to use dynamic sql
this will only work for tables that have an IDENTITY column and it
has the same name for all tables
and so on

The table ALL_CONS_OBJ_COLUMNS table does not have data

I'm trying to obtain data from de data dictionary that Oracle provides to its databases. When I execute the query:
SELECT TABLE_NAME
FROM ALL_CONSTRAINTS;
I get the names from the tables I own as user and the tables other users have granted me access to (Around 130). Now, when I try to execute
SELECT TABLE_NAME
FROM ALL_CONS_OBJ_COLUMNS;
I get nothing, the result is an empty table. Does that make sense? As the docs says "displays information about the types that object columns (or attributes) or collection elements have been constrained to, in the tables accessible to the current user.", I think it should display the same table the previous query did.
I was wrong: I'm looking for ALL_CONS_COLUMNS. That table does not have all the names of the preiovus one, but has the ones I need. I guess I not fully understand the notion of objects yet.

How to Merge Multiple Database files in SQLite?

I have multiple database files which exist in multiple locations with exactly similar structure. I understand the attach function can be used to connect multiple files to one database connection, however, this treats them as seperate databases. I want to do something like:
SELECT uid, name FROM ALL_DATABASES.Users;
Also,
SELECT uid, name FROM DB1.Users UNION SELECT uid, name FROM DB2.Users ;
is NOT a valid answer because I have an arbitrary number of database files that I need to merge. Lastly, the database files, must stay seperate. anyone know how to accomplish this?
EDIT: an answer gave me the idea: would it be possible to create a view which is a combination of all the different tables? Is it possible to query for all database files and which databases they 'mount' and then use that inside the view query to create the 'master table'?
Because SQLite imposes a limit on the number of databases that can be attached at one time, there is no way to do what you want in a single query.
If the number can be guaranteed to be within SQLite's limit (which violates the definition of "arbitrary"), there's nothing that prevents you from generating a query with the right set of UNIONs at the time you need to execute it.
To support truly arbitrary numbers of tables, your only real option is to create a table in an unrelated database and repeatedly INSERT rows from each candidate:
ATTACH DATABASE '/path/to/candidate/database' AS candidate;
INSERT INTO some_table (uid, name) SELECT uid, name FROM candidate.User;
DETACH DATABASE candidate;
Some cleverness in the schema would take care of this.
You will generally have 2 types of tables: reference tables, and dynamic tables.
Reference tables have the same content across all databases, for example country codes, department codes, etc.
Dynamic data is data that will be unique to each DB, for example time series, sales statistics,etc.
The reference data should be maintained in a master DB, and replicated to the dynamic databases after changes.
The dynamic tables should all have a column for DB_ID, which would be part of a compound primary key, for example your time series might use db_id,measurement_id,time_stamp. You could also use a hash on DB_ID to generate primary keys, use same pk generator for all tables in DB. When merging these from different DBS , the data will be unique.
So you will have 3 types of databases:
Reference master -> replicated to all others
individual dynamic -> replicated to full dynamic
full dynamic -> replicated from reference master and all individual dynamic.
Then, it is up to you how you will do this replication, pseudo-realtime or brute force, truncate and rebuild the full dynamic every day or as needed.