Database Design and relation diagrams details - sql-server

We have a production SQL Server and my desktop has SQL Server 2008 R2 Management Studio software installed. I have recently been given a task to perform data mining on our server DBs.
We have around 100 or more of tables there and it is getting very difficult for me to see how tables are related or has been created.
For a particular scenario I have cornered to 3 tables amongst the 100's that we have - but I cannot formulate how these tables are related with each other. I mean if only I know that one's table column is PK / FK of other then only I can execute something like below to extract data's -
SELECT *
FROM tablea,tableb
WHERE tableb.id = tablea.id
and do data mining on the result data set.
Please let me know how can I get all the tables and it relation details? What tool I can use such that further on information like above can be extracted or database designs can be known?
I tried to create the DB diagram but it showed me below error:
Do I need to install any other tool?
Below is my MS SQL Studio version details:

I think your solution is to use a database diagram (https://msdn.microsoft.com/en-us/library/ms189078.aspx)
Just drag all tables on the screen and it will show you the relations, this of course only when the primary-keys/foreign-keys are there.
For the error you are getting:
if I google that for you I get:
The backend version is not supported to design database diagrams or tables
The answer marked as the solution is:
This is commonly reported as an error due to using the wrong version
of SMSS. Use the version designed for your database version. You can
use select ##version to check which version of sql server you are
actually using

Related

Can in-memory tables be added to a database diagram

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

Migrate data to another database with different object names

We are working on a project to migrate our Oracle database to SQL Server. There are many off the shelf products that seem to do this such as Microsoft SQL Server Migration Assistant & Navicat premium for example.
One of the requirements of this migration is that we are changing the naming convention of the tables & columns as part of the transition.
In Oracle we currently have adopted the naming convention of:
Table: T_USERS, T_REPORTS, T_USERS_REPORTS etc.
Columns: USER_ID, CREATE_DT etc.
While moving to SQL Server we wish to adopt a SQL Server specific naming convention (Camel case):
Table: Users, Reports, UsersReports etc.
Columns: UserId, CreateDt etc.
Both of these tools mentioned seem to only create a SQL Server object with the exact same table & column names as part of the data migration process. Is it possible to create this sort of mapping with either of these two tools? Or is there a better tool available?
Both of these also do not feature incremental data migration. They are designed to completely clean out all records and then migrate all data. This is obviously not ideal for performance. Is there a tool that has a delta type migration where it will compare existing records on both target and source destinations?

Column check SQL Server

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.

Migrate Oracle partitioned tables to SQL Server

I need to migrate about 700 Oracle partitioned tables (RANGE and LIST partitioning) to SQL Server.
Turns out the SSMA (SQL Server Migration Assistant) does not handle Oracle partitioned tables (this is the official answer I got from Microsoft).
Any tool / script / other suggestion to automate this process?
Thanks!
They are correct:
Tried to do this for a project last year for work and found out the same thing:
Tried doing a little research on google to see if things have changed but found out the following:
Migration of Oracle Partitioned Tables is not supported by SSMA. Partitioned tables are migrated as a Non-partitioned simple tables.
Partitioning of the these Tables in SQL server is required to be done manually as per the physical database architecture planning and logical drives of the server system.
Any partition maintenance (adding or dropping or truncating the partitions) related code need to be re-rewritten in SQL Server."

SQL Server 2005 Auditing

Background
I have a production SQL Server 2005 server to which 4 different applications connect and make changes.
There are no foreign keys and in some cases no primary keys.
Unfortunately throwing the whole thing out and starting from scratch is not an option.
So my solution is to start migrating each of the applications to a service layer approach so that there is only one application directly connecting to the database.
However there are problems that need to be fixed before that service layer is written and all the applications are migrated over.
So rather than make changes and hope they don't break any one of the 4 badly written applications (with no way of quickly testing all functionality) my solution is to start auditing the database
Problem
How do I audit what stored procedures, tables, columns, views are being accessed/updated/called by each user on SQL Server 2005.
I can find out which tables are being updated but I have no idea which columns and by what users.
I also don't know if certain tables are being accessed only through stored procedures/views.
I know that SQL Server 2008 has better auditing features but if I could do this without spending money that would be great. That said if the best solution is to upgrade or buy software that's also an option.
Check out SQL Server 2008's CDC feature. You can't use this directly in 2005 but you can write a trigger for each table to log all data changes to a new audit table. i.e. you'd have an audit table for each table in your db, with all the same columns plus some additional columns saying what the operation was and when it occurred.
If the nature of your applications means you can get user information and/or application information from CURRENT_USER and APP_NAME() you could include that information in the audit table too.
And check out this answer for more goodness.

Resources