SQL Server Management Studio Issues - sql-server

I accidentally deleted YEARS of data in SQL Server Management Studio from a table. Unfortunately the person in this position before me didn't back anything up. Nor did I before I tried to fix an issue. I understand that it cannot be retrieved from SQL but I have all the data I need in a separate file on my desktop. Is their anyway to get that data and input it back into the table that is in SQL? Or is there a query I can run to input the data again into the table? I'm not sure if I am making any sense :/

You can also used Management Studio without SSIS. Right click on the database in MS and select Tasks -> Import Data. You should then be able to select the type of source (flat file) and the format. The rest of the wizard is pretty self-explanatory.

If it is a flat file like .txt or .csv or even an Excel file like(.xls), you can build an SSIS package and dump the data to a new table. Depends, on what kind of data you have in your hand.

Related

How to export data from SQL without using the import/export wizard?

I need to export data from SQL to csv or Excel without using the wizard. It must be done through query. I looked a lot online, but could not find a solution. The best solution I found was to use a command code to export the data, but this returns the data without headers. Please help !
Edit:
I am new to SQL, and really been researching this for a while. I therefore would be grateful if you can give me the code to do this in SQL management studio (if possible). Many thanks !!!
Rather than pushing the data out from SQL Management Studio, you could create a connection to the database within Excel and pull the data in.
In Excel, choose Data > From Other Sources > From SQL Server (or Data > New Query > From Database > From SQL Database)
Select the database, database table etc.
If you need to filter or otherwise manipulate the data rather than pull in the whole table, then you can go to the Connection Properties dialog afterwards and enter whatever SQL you want into the Definition tab. For instance select * from <table> where <field> = "value".

Export excel data to sqlserver

What's the correct way of exporting data from Excel 2013 file to SQL Server database? The data from the Excel file should be transferred into SQL when saving excel file to a database.
I know many answers for this are available but my question is bit different: every time the excel data changes, or the user clicks on save button the data in the database also needs to be updated.
The easiest way to do this is with an SSIS package. SSIS (SQL Server Integration Services) is a package built in to SQL which allows transformations between data formats.
You can create a package by right-clicking on your target database in SQL Server Management Studio and selecting Tasks > Import Data. In the wizard that comes up asking for a data source choose "Microsoft Excel" from the top drop-down labelled as Data Source, then follow the wizard through. You'll have the choice of importing the Excel data into a new table or mapping it into an existing table.
If you want do this programmatically, you can save your package at the end of the wizard and then invoke it via code. But that's a different question.
What you want is not possible (as long as I know off). You can use SSIS package to migrate the Excel sheet into SQL Server, but is imposible to determine if someone "click save" or do some changes on the excel file. SSIS package can be programed to run on schedule or by demand. You should investigate SSIS packages. It is not easy to learn, but do what you need.
Maybe you would like to try a tool I have developed? It's an Excel Add-In that exports Excel data to SQL Server.
There is a feature to automatically export the data to SQL Server every time you press the save button in Excel. If you need to update the database every time a cell value change, you will need to add a few lines of VBA-code that will push the data to SQL Server.
To beta testers I currently give away a free license, so if you are interested in testing it out, send me an email:)
www.sqlpreads.com

CSV - SSIS - SQL Server, Character Encoding Problems

I have a large set of CSV files which I am transferring to Microsoft SQL Server 2014 Management Studio. I am using a SSIS package in Microsoft Visual Studio 2012 to achieve this. I currently have around 2 million lines of data so I need SSIS
The problem I have is that while the data in my CSV already has encoding issues I am making them far worse in transit.
For now what I need to do is just maintain the characters so that whatever I see in my CSV appears in my SQL server table. I am particularly interested in 'Benoît' which is fine in my CSV but not in my SQL table where it becomes 'BenoŒt' Please see the list at the bottom of my post.
I am also wondering if once I have imported the data in its current state I can reliably use find and replace to deal with the existing encoding issues from my CSV's
Character encoding is a confusing subject and I am not all sure if a couple of paragraphs can put me on the right track. Please help with a steer (if its possible!) I am sure I need to look at the settings across both SQL server and Visual studio but am not sure what needs a tweaking or where..
"Benoît" in my CSV becomes "BenoŒt" in my SQL table
"Angélique" in my CSV becomes "AngÇŸ¶¸lique" in my SQL table
"Michèle" in my CSV becomes "MichÇŸ¶ùle" in my SQL table
"josée" in my CSV becomes "josÇŸ¶¸e" in my SQL table
"Amélie" in my CSV becomes "AmÇŸ¶¸lie" in my SQL table
First of all make sure that your CSV files are in the Unicode encoding (try to open CSV file in the Notepad-> Save As -> and check Encoding in the bottom). If they are not - save them in Unicode
And make sure that in the Flat File Source properties inside SSIS packege the Unicode check box is selected
Your csv file needs to be in UCS-2 Little Endian encoding.
Please open it in notepad++ to check.

Import database (SQL file) in SQL Server Management Studio

I've created the structure of my database first in PhpMyAdmin and exported it to a .sql file.
Now I'm looking everywhere in SQL Server Management Studio where I can import/add the data in a new database.
Does anybody where to look or what to click?
I'm using the 2014 version (CTP2)
If you have a .sql file which contains SQL statements, you can just copy and paste the contents (or open the file in a query window) and run it. This assumes it has all of the create table etc. statements to create the schema/structure and not just insert statements for the data.
Check the top of the file to make sure that it is first selecting the correct database, if not add a USE statement to select the correct database.
You didn't say how big the file was, but if it is quite large and has the insert statements (data as well as schema), then you'll probably want to run by CLI using sqlcmd command. Much faster and SSMS won't freak out.
Another alternative option to running the .sql file/code is to set up a data source for mysql and just use odbc to access the database itself.
Bear in mind that there are real and very annoying differences between mysql and t-sql that can make migration a pain. If you're just creating a few tables, it may not be an issue, but if there are a ton of tables with lots of fields of different data types, you may run into issues.
If you are looking to import table structure, you can copy-paste the content and run inside SSMS in a query window. Beware of syntax differences with MySQL and SQL Server. You will most likely get errors. You need to convert your SQL script from MySQL dialect to SQL Server dialect (or just add them manually if they are not too many). If you set the databases to a SQL standard-compatibility mode at the very beginning, you will have much less trouble.
If you are ONLY looking just to import the data into existing tables inside the SQL Server only, you can do the same (i.e. copy-paste and run in query window). You will have less trouble with that.
Open the server, open "Databases" and right click the database, go to "Tasks" and then Import Data...
I have had the most 'trouble free' success importing to SQL via a flat file method (comma delimited .txt file), the only stipulation when creating a flat file (i.e from Access) make sure the text identifier is set to {none} and not "".
To import the file: in the SQL Server Management Studio right click on Databases and create a new database. Then right click on the new database -> Tasks -> Import Data... The import window opens: in the DATA SOURCE option select Flat File Source and select the .txt file...click NEXT. In the DESTINATION field select SQL Server Native Client 11.0 and go through the import process. This worked very well for me.

How can i export table data with column name in text file in sql server 2005?

How can i export table data with column name in text file in sql server 2005?
safest way to do that is to backup data and then restore it on other server!
right click on database in ms sql management studio>tasks>backup , choose directory to backup the file. Zip it ( saves a lot of space) move to other location, create database with the same name right click on database>tasks>restore.
In backup and restore always choose overwrite in options menu otherwise it will be appended to existing dataset.
Other way to do that is right click on database, tasks, export data and move it to another location. more advanced though, backup works faster and you supposed to use it unless you want partial move, like some tables and some stored procedures.
If it's a small amount of data, you can upgrade your Management Studio to SSMS 2008 (you do not need to upgrade your server). The Results tab has the ability to copy data with headers, so you can cut and paste into Excel.
A larger amount of data can be extracted in several ways such as an SSIS package, the Import/Export wizard, or doing a pull through ODBC from Excel.
You can do this using an SSIS package.

Resources