I have two databases, one is on SQL Server and the other is on PostgreSQL. Is there a way to join tables from these two database, or, if not possible, is there a way to pull from both databases and put the result in a temp table?
Thanks!
Foreign Data Wrapper
PostgreSQL supports Foreign Data Wrappers, per the SQL standard. See the wiki.
The easy way, use FDW for SQL Server and see remote SQL Server table like a local table.
You could create link server, see below link for more details:
https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine?view=sql-server-ver15
Related
I have a SQL Server 2016 database with in-memory tables. I'd like to use the database diagram feature to create a graphic to match.
Running SSMS 18.3.1. When I start a new diagram, the in-memory tables are not shown in the drop down. Is there another way to get them on the diagram?
Note: In the official documentation these are called memory-optimized tables. See Introduction to Memory-Optimized Tables
You can't add OLTP object in Database Diagram, not in even in SQL Server 2019.
I thought there should be a way to modify [definition] column in [dbo].[sysdiagrams] but it is HexString of unknown file type. (I tried many formats but its obviously an internal Microsoft type)
Unfortunately, there is no reference to mention that is a not-supported feature. (I send a comment to this page )
OLTP is not supported for database diagram. You do not have access to in-memory tables in the diagram because the diagram does not recognize the essence of a in-memory tables as a table, in fact SQL Server generates a DLL for each created Memory-Optimized Table Type that includes the functions required
for accessing the indexes and retrieving data from the related Memory-Optimized Table Variable
If you run the SQL Profiler tool you'll see there is a column name IsMemoryOptimized in the table data result set that is returned for the memory-optimized table. I think since the Database Diagrams functionality is older (since mssql 2000) and not updated regularly it does not support viewing the newer memory-optimized tables.
more info here:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/71aa7b6e-c281-4417-8149-2eb6f3830110/sql-server-2016-memory-optimized-tables-not-visible-in-database-diagrams?forum=sqlinmemory
I have a lot of views and tables connected in Microsoft SQL Server. I want to check all the useless columns I have in the native tables. Is there a way to perform an automatic check if a column in a table is used or not in other tables?
Create a database diagram in SQL Server Management Studio. From here you can analyze how the tables/columns are related or not. Info here
Do a business model analysis and see which values are used, which are deprecated and start from there.
If you do any changes on the database, these changes have to be projected in any code connecting to that database.
Do not remove columns in tables just by looking at a database diagram. You would destroy any object-relational mapper.
I am new to SQL Server. On the previous job I used working with Postgres and MySQL. But now I was faced with the task connected with SQL Server. And I discovered very strange thing in the DB with that I should work. There don't exist any relations!
Is it normal to SQL Server? How can I automatically connect tables according to their primary keys? Any other ideas?
An screenshot of the ER diagram:
Unless you are talking about creating hundreds of FKs you may be better off by just adding those relationships manually either through SSMS database diagram or through a sql script.
If the number of possible relations is really large or you expect to have to do this again in the future, you may want to look to SMO (SQL Management Objects) and either use Powershell or a small C# program to script out the tsql that would join those tables. But you would need to make sure that there is a repeatable pattern / naming convention between the columns and tables that you can leverage. For Example:
Table1
ID
Name
Table2
ID
Table1ID
Name
Here you could consider Table1ID as a FK referencing Table1.ID
I have a third party Sql Server data, which I need to use as a data source for my custom database, without duplicating data.
One thing, which comes to mind is to create a View in my custom database, which would reference one or more tables from this third party database.
Is this possible with Sql Server 2014?
Yes, as long as they're on the same server, TSQL: Create a view that accesses multiple databases . If they're on different servers, then you'd have to create a linked server, which I wouldn't suggest unless you're aware of the pitfalls.
Yes very much it is possible but you need to fully qualify the table name like
create view testview
as
select * from db_name.schema_name.table_name
Is it possible to replicate 2 SQL Servers on table level? (I want to replicate only few tables, not all DB). Both SQL Servers work on different physical servers and should synchronize a few tables.
If it is possible, how to avoid conflicts?
Thanks!
Yes you can use MERGE Replication provided both source and destination table names should be same.I guess transactional replication might support if table names are different.