SQL Server entity tables and storedproc automation tools? - database

Are there any automation tools to ease creation of tables and adding standard insert/select/update stored procs, rather than doing hand creation for a large number of tables ?
If i have 100 tables to create (and later ALTER) and their associated stored procs in SQL Server 2008, what is the most convenient way to do it ?
ADDED:
Are there tools to auto-generate nice class skeletons (with data fields) tied-up with corresponding tables ?
I am using C# .NET 4.0 in Visual studio 2010 and Microsoft SQL Server 2008.
We are starting off a new project from scratch, so it would be helpful to get tools for quick bootstrap from Design on paper to initial code.
Any other related suggestions are appreciated!

Use SSMS Database Diagrams to design you 100 tables because one only has to type the column name and can point and click for data type, primary key, nullability, foreign key, etc. Create a diagram for each functional grouping. When the design is done you can write a script which will write the SQL for the stored proc to do the insert/update for the tables.
As you create the script to write the script you could post your work here.

Related

How/what to import to dbdiagram.io?

Hey I'm pretty new to databases and I want to create a diagram of the db I'm using with dbdiagram.io so that I can't understand the relationships better. What sort of script/file am I supposed to use to import the schema from sql server? I'm currently using azure data studio to query the database. I would prefer not to have to write out all the tables by hand.
Based on the docs and the DBML language, you need to generate a DBML script in the following format from your RDBMS of choice - in this case, SQL Server:
Table Users {
UserID integer [pk]
}
Table Posts {
PostID integer [pk]
UserID integer [ref: > Users.UserID] // many-to-one
}
Note that this DBML output is not intended to run on your RDBMS, SQL Server or otherwise - those platforms don't understand DBML. It is an example of output you need to generate from your RDBMS that you can paste directly into the left editor pane on dbdiagram.io, as demonstrated here.
This more complicated example - which uses DBML to build a diagram from SQL Server based on a subset of the tables in Stack Exchange Data Explorer (and which I described here) - took about 40 seconds to create.
You can build this syntax from a set of tables without having to hard-code each one using catalog views like sys.tables and sys.columns, but there are a lot of little things that you'll have to do to make it compatible with this web site, and that will be a project all its own. Basically, nothing in SQL Server exists to generate nice, tidy DBML for you.
If you don't want to use DBML but would rather use the Import feature on the web site, then you can generate traditional DDL scripts instead - from SQL Server, you can do this by right-clicking the database in SSMS / Object Explorer and using Script Database as > CREATE To. Azure Data Studio doesn't yet have this functionality, but you can use an extension.

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?

copy data from one table to another with different primary key

I have to migrate data in sqlserver from one table to another. Most of the standalone table were possible with select and insert into sp's.
The issue is in one table from the old database there is a column with a primary key say unit.
Now this unit is divided into two parts in the new database for example 'industry' and 'resource'.i.e industry + resource together constitute the unit.
How can i go about with the migration of this.
I have done similar "Database Transformation" tasks with SQL Server Integration Services it does require that you have SQL Server Standard or Enterprise (not Express) but because it is part of SQL Server there is no additional licencing, if it isn't installed you may need to re-run the installer and select "Integration Services".
SSIS will allow you to create a data flow, aranging the data more or less how you want it. There are several tutorials on MSDN.

SQL Command for generating schema text (similar to CreateTo or AlterTo)

SQL Server 2005. Is there a sql query that will return a text field containing the same type of schema info as you would find in doing a right click table -> Script Table As -> Create To (or Alter To) from SQL Server Management Studio ?
I'm looking for a single/flat format that describes the entire table, including constraints, indices, etc.
I am aware of:
sp_help table_name
but that doesn't provide the single flat format I'm looking for. Ideally it would be in a scriptable format, such as the AlterTo result that could be executed against the server.
This is for a scheduled process that documents table schemas on a nightly basis for checking in to version control (SVN).
Not really. A table def is a collection of columns, constraints etc.
There is an SVN plugin that may help called ScriptDB4SVN. I've not used it personally, I'm going on hearsay.
Was searching the 'net again for an answer to this, and came across this SO question. It doesn't accurately capture all the same data as SQL Management Studios Create-to, but enough for my purposes (scripting the database structure for version control purposes).
There is no such command in SQL Server. This is primarily because the Scripting facilitiy is actually in SMO and not in SQL Server itself. There are a number of free console command-line tools that can do it that you could call via xp_CmdShell.
However, if you really want to do this from T-SQL, then you will need a script or stored procedure that enumerates all of the tables attributes, columns, column datatypes, defaults, nullabilty, etc. etc. and then reassembles it into a CREATE TABLE script. This is a Huge task. That's the bad news. The good news is that someone (Lowell Izaguirre) has already done this and posted it in this article (http://www.sqlservercentral.com/scripts/Miscellaneous/30730/) at SQLServerCentral.Com.
Enjoy.
Not really - you can either use C# (or VB.NET) and SMO (SQL Management Objects) to script out your database objects (tables and all), or you can use SQL to get the list of columns for a table:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Your Table Name here'
But I don't know of any easy way in SQL itself to create Create/Alter scripts for database objects, sorry.
Marc

Resources