Can I dump an entire Microsoft SQL Server database from Linux? - sql-server

I've got a linux server that already connects happily to a MS SQL Server and I want to know if there is a way to dump the whole thing into a format I can read. I don't have access to the desktop, but I can connect using PHP and I can issue whatever commands I want. I have admin access to the SQL Server, so no problem there.
My main goal is to understand how the people before me set this thing up. I already know how to get the stored procedures as text (SELECT * FROM sys.procedures), but I was wondering if there is a way to get the whole database. I'm not very familiar with SQL Server so I don't know what important bits I might be missing.
And I don't care if the solution is in PHP or not. That's just the thing I've got working right now. Any SQL-ish command that dumps the entire database would solve my world.
To summarize:
I don't have access to the actual machine/desktop
I have admin access to the DB using PHP's mssql libs
I'm on linux
I want a text file I can look at that tells me everything in the database
My goal is not to answer a specific question - I'm looking to understand what the people before me did when they set up this database. Unknown unknowns, and all that.
Okay, hopefully I've made sense. I'm sorry if I've been a complete idiot. Be gentle. Thanks!

I would backup (http://msdn.microsoft.com/en-us/library/ms186865.aspx) the database to file and then download it, restore it on Windows and then use SQL Server tools like SQL Server Management Studio etc. to look at it.
There is plenty you can do with the metadata, but you could spend a lot of time writing queries instead of using existing off-the-shelf documentation tools.

You can use this script to create insert statements for any given table.
This stackoverflow question will tell you how to generate create table statements.
SELECT NAME FROM sys.tables will give you a list of table names.

You would probably save a LOT of time and pain by just using native SQL SErver Windows tools that work with it.

Related

How to capture flat file timestamps in SSMS

This is my first attempt to ask a question on this forum. I'm currently running a local instance of SQL2008 R2 on my machine. I have Googled many different ways to get this exact question answered but had no luck so far.
Simply put, I want to know how to capture a Windows flat file (foobar.txt) timestamp using t-sql code. I am totally new to MS SQL, and so far all I have run across is an undocumented sp called "xp_DirTree" which comes close but doesn't give me what I need. Is there a simple function that I'm overlooking here?
In SSIS there is a Logging feature. Create a new connection for Logging and link to the SQL Server database. You can select what features should be stored in the new table. The new table created will be named as "sysssislog" inside System Tables.

Custom sync through different SQL servers?

I am currently working on a project, where every user has to have its own local database on his laptop in order to go offline and work on the road. Whenever he comes back to the office, he plugs in his network cable and syncs the database manually with the master database.
I am looking for an easy "1-click-solution" with already presetted sync configurations.
So for example, I'd like to sync all data in my tables except some certain ones. Though, all stored procedures need to be synced.
It needs to be executed by arguments, so I am able to make it run kinda as a script e.g. everytime the user logs in.
PS: I heard that the red gate tools are pretty good. What do you guys think of it?
You might want to try using the SQL Compare and SQL Data Compare command lines to achieve this.
In your SQL Data Compare project file you can select specific tables and save this in a project file, and reference this from the command line. Or you could use the /include and /exclude switches.
Here is documentation to the SQL Compare and SQL Data Compare switches.
You can post questions on our forum if you need any assistance.

SQL Server source control

I'm planning to use source control for SQL Server database. I have different versions of SQL Server (2005 and 2008) running on different machines (Windows 2003 and 2008). I looked up about source control and found out 2 options.
http://nobhillsoft.com/Randolph.aspx
http://www.red-gate.com/products/sql-development/sql-source-control/
So I was just wondering if someone have experience with them and suggest me which one would be good out of these or any other better option?
Thanks!
In my opinion, you may be approaching something here from the wrong angle. If you try to revert a change to the table structure, but the table has been populated with data fitting the new table structure, what happens? It's more complex than maintaining plaintext diffs. I encourage you to really look at the idea and see if you can accomplish this another way, and document your database design as completely as possible every time you need to change it.
That being said, here are some more ideas.
http://www.sqlservercentral.com/Forums/Topic753558-361-1.aspx
http://www.sqlservercentral.com/Forums/Topic635185-145-1.aspx
I compare all these options and going with Red-gate source control and data source solution. Thanks for all suggestions!
You can use your current version control system if it's suitable for you to store only installation SQL script of a database.
Use SSMS to produce installation script: right-click on desired databased, select Tasks -> Generate Scripts... Script Wizard will start and help you to script any objects you need in the database including data. Save this script under your version control system since it's text file.
Use this database installation script to reproduce the database at desired location and environment.

migrate data from MS SQL to PostgreSQL?

I've looked around and can't seem to find anything that answers this specific question.
What is the simplest way to move data from an MS SQL Server 2005 DB to a Postgres install (8.x)?
I've looked into several utilities like "Full Convert Enterprise", etc, and they all fail for one reason or another, ranging from strange errors that make it blow up to inserting nulls rather than actual data (wth?).
I'm looking at a DB with all table except for a single view, no stored procs, functions, etc.
At this point I'm about to write a small utility to do it for me, I just can't believe that's necessary. Surely there's something somewhere that can do this? I'm not even too worried about cost, although free is preferable :)
I don't know why nobody has mentioned the simplest and easiest way using robust MS SQL Server Management Studio.
Simply you just need to use the built-in SSIS Import/export feature. You can follow these steps:
Firstly, you need to install the PostgreSQL ODBC Driver for Windows. It's very important to install the correct version in terms of CPU arch (x86/x64).
Inside Management Studio, Right click on your database: Tasks -> Export Data
Choose SQL Server Native Client as the data source.
Choose .Net Framework Data Provider for ODBC as the destination driver.
Set the Connection String to your database in the following form:
Driver={PostgreSQL ODBC Driver(UNICODE)};Server=;Port=;Database=;UID=;PWD=
In the next page, you just need to select which tables you want to export. SQL Server will generate a default mapping and you are free to edit it. Probably you`ll encounter some Type Mismatch problems which take some time to solve. For example, if you have a boolean column in SQL Server you should export it as int4.
Microsoft Docs hosts a detailed description of connecting to PostgreSQL through ODBC.
PS: if you want to see your installed ODBC Driver, you need to check it via ODBC Data Source Administrator.
Take a look at the Software Catalogue. Under Administration/development tools I see DBConvert for MS SQL & PostgreSQL. Probably there are other similar tools listed.
You can use the MS DTS functionality (renamed to SSIS in the latest version I think). One issue with the DTS is that I've been unable to make it do a commit after each row when loading the data into pg. Which is fine if you only have a couple of 100k rows or so, but it's really very slow.
I usually end up writing a small script that dumps the data out of SQLServer in CSV format, and then use COPY WITH CSV on the PostgreSQL side.
Both those only take care of the data though. Taking care of the schema is a bit harder, since datatypes don't necessarily map straight over. But it can easily be scripted together with a static load of the schema. If the schema is simple (just varchar/int datatypes for example), that part can also easily be scripted off the data in INFORMATION_SCHEMA.
Well there are .NET bindings for MS SQL Server 2005 (obviously) and also for PostgreSQL. So it would only take a few lines of code to code up a program that could transfer data safely from one to the other. The view would probably have to be done manually as Postgres doesn't use the same language for views as SQL Server.
This answer is to help summarize current connection string because someone may overlooked the comment.
Current version of ODBC connection string is:
For 32-bit system
Driver={PostgreSQL UNICODE};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
For 64-bit system
Driver={PostgreSQL UNICODE(x64)};Server=192.168.1.xxx;Port=5432;Database=yourDBname;Uid=postgres;Pwd=admin;
You can check the driver name by typing ODBC in windows search.
And open ODBC Data Source Administrator

Is there a simple tool for adding users to a SQL Server database?

I'm looking for a simple tool, preferably one that I can redistribute with my application, that non-technical end-users can use to add users (and logins if necessary) to a particular SQL Server (Express) database.
Obviously SSME will do the job, but I don't want to require users to install something so heavy-weight.
I have a good idea how I would write this myself using SQL Management Objects, but I'm looking for something pre-built.
Any ideas?
To be honest, I wouldn't expect you to be able to find such a tool - the scope of it is too narrow - you want something with the power to create and edit Logins/Users, but be simple enough for laymen. Would you want such a powerful tool in the hands of such people? Apart from SSMS, there will be a number of 3rd Party clients for SQL Server, but you need something simple to use and locked down - I just don't see it happening.
However, I might be wrong - just because I haven't come across such a thing, it doesn't mean they don't exist.
I don't see why you can't build simple features into your application to add new users/logins. It seems the most sensible suggestion. Apart from SMO, is there any reason why you couldn't use CREATE LOGIN/CREATE USER T-SQL commands?
Create User
Create Login
You can write you own tool using the managed .NET Libraries SQL Server Management Objects (short SMO). They are shipped with .NET Framework 2.0 i think. So it should be no problem with dependencies.
SMO gives you full control over SQL Server. MS SQL Server Management Studio is also written based on these libraries.
edit: There is nothing, from what I can see. People normally build it into their application.

Resources