Copy from MySQL Workbench to Excel - mysql

I have to build reports, and I need to do some database queries, which return a bunch of results.
Is there a way I can copy 1+ rows/columns and copy them into an excel sheet? the excel sheet is formatted a particular way, and the data needs to be placed in there a certain way, so how can I copy and paste from mysql workbench into excel?

The best answer I could come up with is to use a different program:
http://www.heidisql.com/
So far this program works great! I like it a lot better than MySQL Workbench as well!

Go to workbench and select the rows that you need. Copy them.
On your pc create a new file, paste the data in it. Save it as .csv
Open the newly created csv file in MS Excel. The data will be nicely formatted.

In my requirement I have to copy the column name, data type and its constraint.
I executed command
desc tableName
Where tableName is required table name.
in heidisql to execute query you have to press "F9" key.
It will display the whole structure of table. Now to copy paste in excel you have to right click on result then you can see
"export grid rows"
third last option in right click.
then select radio button File then select file name.
No need of any alteration in encoding part and you can select from output format e.g. excel csv, html table etc.
and then ok.
Go and open your file then complete result will be copied to the excel sheet.
Thanks

Related

SSIS - Exporting data with commas to a csv file

I am trying to export a list of fields to a csv file from a database.
It keeps putting all the data onto one column and doesn't separate it. When checking the preview it seems to be okay but on export its not working. Currently trying to following settings. Any help would be appreciated.
SSIS settings
Excel file output issue
Actually it seems to work, Excel is just too dumb to recognize it.
Mark the whole table, then go to Data -> Text in Rows
And configure the wizard (Separeted, Semikolon as Separator):
Now you have seperated the rows and cells:

create table in DB from excel data in sheet

I need help creating table in DB through Excel.
User has table in excel sheet, which has not exact count of columns. User can add or reduce columns and of course add or reduce rows too.
I need a script for example for ODBC Microsoft Query which choose all table range in excel sheet and create table with this data in DB (MySQL).
It has to work on a one click not manually.
Thank you
This is solution for me. It's not exactly what I wanted, but it's enough for me now. After some modifications, it works on MySQL.
tomaslind.net - export data excel to sql server

Erasing records from text file after importing it to MySQL database

I know how to import a text file into MySQL database by using the command
LOAD DATA LOCAL INFILE '/home/admin/Desktop/data.txt' INTO TABLE data
The above command will write the records of the file "data.txt" into the MySQL database table. My question is that I want to erase the records form the .txt file once it is stored in the database.
For Example: If there are 10 records and at current point of time 4 of them have been written into the database table, I require that in the data.txt file these 4 records get erased simultaneously. (In a way the text file acts as a "Queue".) How can I accomplish this? Can a java code be written? Or a scripting language is to be used?
Automating this is not too difficult, but it is also not trivial. You'll need something (a program, a script, ...) that can
Read the records from the original file,
Check if they were inserted, and, if they were not, copy them in another file
Rename or delete the original file, and rename the new file to replace the original one.
There might be better ways of achieving what you want to do, but, that's not something I can comment on without knowing your goal.

Import Excel to SQL Server 2008

I need to create a process to import a multi tabbed excel spreadsheet into SQL Server 2008R2. Each tab will be a different table in the database. This will need to be done weekly and imports should be automated. Ideally I want to pop the spreadsheet into a folder [or have some intern do it] and have sql run a procedure that looks in this folder, and adds the data to the tables in this db. I would also like to have another table that tracks the imports and date stamps them. I really have no idea where to even start here as I'm a pretty huge noob when it comes to tsql.
There is a nice article by microsoft - http://support.microsoft.com/kb/321686 - that outlines the processes involved.
The process is simply
SELECT * INTO XLImport3 FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\test\xltest.xls;Extended Properties=Excel 8.0')...[Customers$]
Where XLImport3 is the table you want to import into and the datasource is the excel sheet you want to import from.
If you're limited solely to TSQL, the above two answers will show you some ideas. If you have access to either Data Tools or Business Intelligence, with SSIS, you can automate it with the assumption that each sheet in the Excel workbook matches each time. With SSIS, you'll use a Data Flow task and each sheet will be imported into the table that you want. When you're ready for the file the next week, you'll drop it into the folder and run the SSIS package.
However, if the sheet names change, (for instance, one week sheets are called Cats, Dogs, Rain and the next week it's Sulfur, Fire, Hell) then this would cause the package to break. Otherwise, if only the data within the worksheet change, then this can be completely automated with SSIS.
Example article: https://www.simple-talk.com/sql/ssis/moving-data-from-excel-to-sql-server---10-steps-to-follow/
Below is the code to insert data from a csv file into a given table. I don't what the full requirements are for the project, but if I were you I would just separate each table into a different file and then just run a proc that inserts data into each of the tables.
BULK
INSERT TABLE_NAME
FROM 'c:\filename.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
insert into import_history ('filename', 'import_date') values ('your_file_name', getdate())
Also, for the table that tracks imports and timestamps them, you could just insert some data into that table after each bulk insert as seen above.
Also, here's a link to tutorial on bulk inserting from a csv file that may also help: http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/
Its very simple. Right click the Database in Sql Server(2008), select Tasks and select Import Data
Now change the DataSource to Microsoft Excel. Chose the path of Excel file by clicking Browse button and click Next.
Chose the Sql Server instance and chose the database to which the excel to be imported.
Select Copy data from one or more tables or views and click Next.
Now select the sheets to be imported to Sql Server.
Click Next
Now click Finish
Now the wizard imports the data from Excel to Sql Server and click Close.
Here is the table

is there any Query to save the Data in Excel File

I have a table students that contains 100 Records.
Now i'm going to Run a Query
select * from Students
I Copy the Students Data and Paste it in My Excel File
After some Time i inserted another 100 Records now again i'm going to run the Query copy the Data and Paste it in Excel File
Every Time copied and Paste in Excel File.
Is there any Alternate way or Query that directly save the Data in my Excel File
Simplest way would be accessing database table by creating a data connection from excel. I assume you are using Sql server database.
In Excel go to the Data tab
Select relevant data source in the "From Other Sources" drop down
Select Sql server and give necessary conection information and select the table you wanted while navigating through.
Select "Table" as prefered view option and it will show the table in excel.
When a change happen in the database simply right click the excel table and Refresh it