How can I export tables to SQL Script? - sql

I need to export many tables to Script SQL.
I'm using Microsoft SQL Server 2014.
How can I do this?

1) Right click on the database
2) Go to Tasks -> Generate Scripts
3) A Generate and Publish script popup window will appear. Click Next
4) Select specific database objects. And select Tables
5) Go To Adanced, another popup window will be displayed. Scroll down to Types of data script and select Schema and Data
6) And then Save to file or clipboard and click Next

1) Simple Right Click on Database name in object explorer,
2) menu list will be open then from this list go to Task in Task sub menu Click on Generate Script
3) A New Dailog will be opened click on Next button
4) select the tables and any DDL name which you want then click next
5) Then choose path where you save script click next

Related

VBA - Create a menu list when you right click a listbox

I would like to have a menu with two options when user right clicks listbox.
With that menu user would do some actions on selected data, e.g. add new line, change some columns data or delete row. I think I can manage that code but I can not grasp how to create a right click custom menu.
I can not find a way to create such option. Does anyone has an idea?
Here's some code for the right click event:
Select ListBox item on rightclick in Word VBA
Replace this code with your context menu code:
Me.Caption = derivedIndex & " = " & ListBox1.List(derivedIndex)
Here's a example for the popup menu (you need skills to understand Win32 API calls...)
https://www.vbarchiv.net/api/api_createpopupmenu.html
The right click menu on the listbox that created by using only a class(without using Api or Declare function) contains the following buttons ;
Increase Font Size
Decrease Font Size
Sort A-Z
Remove List
Remove All
For VBA codes and sample file review this link

Disable File>Share in Excel with VBA

I need a way to disable the ability for a user to go to (or use) the menu File > Share
I have similar for other save commands like below but need something for this feature as well
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False
I have tried:
Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Share").Enabled = False
to no avail
My aim is to stop users saving copies of this file (Hosted on a server), I fully understand Excel isn't meant to be secure and there is always a way to do this but want to make it as hard as I can for the average Joe
Regards
You could use a for each loop to extract the available commands:
' Iterate available commands from the file command bar.
Sub PrintAllCommandBarControlNames()
Dim cbControl As CommandBarControl
For Each cbControl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print cbControl.Caption
Next
End Sub
Run on Excel 2010, I couldn't find a share option. Might just be my system. The above returned:
&New...
&Open...
&Close
&Save
Save &As...
Single Web Page (*.mht)
Save &Workspace...
File Searc&h...
Per&mission...
Per&mission
Ch&eck Out
Ch&eck In...
Ve&rsion History...
We&b Page Preview
Page Set&up...
Prin&t Area
Print Pre&view
&Print...
Sen&d To
Propert&ies
&Recent File Name Goes Here
&Recent File Name Goes Here
Sign ou&t
E&xit Excel
The 'backstage' menu (that you get when you click top left File menu) is effectively part of the Ribbon, and not a Command Bar. If you tried disabling Save for instance, using your example, you'll find they don't work on 2010/2013 etc.
There is this answer which tells you how to manipulate those menu items in the ribbon: Remove "Save & Send" from File menu in Excel 2010 using custom XML and one of the items is called TabShare.

I dont see the sharepoint lists in the output of power query

I installed the power query add on in Excel and connected the SP site as a data source in excel-power query .After the connection is established , the sharepoint lists are not seen in the navigator pane .
My aim is to export the meta data of all the lists within the site in a single excel .
Problem - if there are 5 lists in the site , I see only 3 in the output of the power query . ( I am one of the owners of the sharepoint site )
If you right click the root in the navigator, click edit, and go to the advanced editor / formula bar, you should see some code like:
= SharePoint.Tables("your.sharepoint.com", [ApiVersion = 15])
Change the SharePoint.Tables to SharePoint.Contents. Now there should be a Lists row you can drill into.

Need help to perform an ETL task with SSIS

I want to connect to a server using its IP address. Then, I want to execute a .sql file kept on that servers drive. I also want to store the results of this sql in a text file on the server itself. Should i execute it as an sql task or run it as an extraction from database or something else ? I am not sure how to go about it. I need tips on how to proceed.
The database used is SQL server 2008.
On SSIS, you can execute SQL and export it to text file(csv).
Please refer this article.
http://dwbi1.wordpress.com/2011/06/05/ssis-export-query-result-to-a-file/
Creating an SSIS Solution on SQL Server to flat file.
Open Microsoft Visual Studio
Click Create Project
Select Integration Services Project
Name the Project (x2)
Set the location, example C:\SSISPackages\
Click OK
Click the Data Flow tab
Click to create a new Data Flow Task
Click the Toolbox tab (bottom left)
Drag OLE DB Source to Data Flow section
Drag Flat File Destination (for example) to Data Flow section
Drag the green arrow to connect the OLE DB Source to the Flat File Destination
Double-click OLE DB Source
Click New next to OLE DB Connection Manager
Select YOURSERVER\YOURDB and click OK
Change Data Access Mode to SQL Command
Enter procedure and parameter(s) (for example) under SQL Command Text
Click Parse Query to confirm the SQL Command is valid, and click OK
Double-click the Flat File Destination
Click New next to Flat File Connection Manager
Choose Ragged Right (if standard fixed-width with CR/LF at end of each row) and click OK
Click Browse and select the destination and file name for the output and click OK twice
Click on Mappings and confirm the input and destination columns are correct, and click OK
To append the current date to the file name:
Click on Package Explorer tab (top right of center pane)
Click on Variables tab (bottom left)
Add a variable called path, Scope = Package, Data Type = String, Value = path to file (not including YYYYMMDD.txt portion of file name)
In the Properties for Flat File Connection Manager (bottom center, right-click), open Expressions, and set Property to ConnectionString and Expression to:
#[User::path]+
(DT_STR,4,1252) DatePart("yyyy",getdate()) +
Right("0" + (DT_STR,4,1252) DatePart("m",getdate()),2) +
Right("0" + (DT_STR,4,1252) DatePart("d",getdate()),2) + ".txt"
(Or however you need the date and file name formatted)
Click Evaluate Expression to make sure it looks OK.

stored proc from excel with parameters

If I create a stored proc in sql that has a parameter, can I run that from Excel?
Without using VBA you can use this method. This assumes your stored procedure returns a result set. It also does not make the parameter pulled from a workbook. I think you'd have to use VBA to do that.
Under the 'Connections' section click 'Connections'
Click Add
Click 'Browse for More...'
Click 'New Source...'
Select 'Microsoft SQL Server'
Click Next
Type in the login credentials and click ok.
Select your database
Uncheck 'Connect to a specific table'
Click Finish.
When asked to select a table just click ok.
This should bring you back to the Workbook Connections screen with your new connection added.
Select it and click 'Properties'
Go to the 'Definition' tab.
Set the Command Type to SQL
set the Command text to the SQL you want to run (i.e. "exec spStoredProc 'value'")
Set a new name for your connection
Click ok.
if told that you are severing a connection just agree that, that is okay.
Click 'Close' on your 'Workbook Connections'
Click 'Existing Connections' under the 'Get External Data' section
Select your connection you just made under the 'Connections in this Workbook' section.
Click Open
Set your Import Data options if you want or just click ok
You should now see the result set from the SQL Query in your excel worksheet.
This data can be refreshed from the data that is in the database by going to the data tab and clicking 'Refresh All'
Yes
A standard ADO call from VBA. Or use the Tools..Data thing.
Sure, you can use VBA.
Or you can do it like this: http://blogs.msdn.com/b/excel/archive/2010/06/08/running-a-sql-stored-procedure-from-excel-no-vba.aspx
Here's another nice article on it.
http://www.itjungle.com/mgo/mgo102203-story01.html
I have been working to find a solution to this for a while now and got the best results from following the steps in this article.
http://codebyjoshua.blogspot.com/2012/01/get-data-from-sql-server-stored.html