Welcome back to this series on SQL Tips. Sometimes I find myself needing to not only generate the DDL for a table but also the data that is stored in that table. For example imagine I have created and populated a few tables for a blog post. It would be much easier if I could share the table definition and the SQL statement to populate that table, Agree? Great!
In this scenario I am going to show you how to generate the DDL to create the DimCurrency table from the AdventureWorksDW2012 database. Along with the DDL script I will also show you how you can generate the script to populate the table.
- Open SSMS and connect to the server where your table is located at.
- Right click on the database where your table is stored, I’m using AdventureWorksDW2012.
- Next click on Tasks
- Next click Generate Scripts
- Inside the Generate Scripts wizard click next on the introduction screen.
- For Choose Objects screen –> Click “Select specific database objects”.
- Expand the tables list.
- Select the DimCurrency Table.
- On the “Scripting Options screen” I’m just going to load the script into a new query window. Please select “Save to new query window”. This option is found at the bottom of the screen.
- On the same screen select the “Advanced” button found on the right side.
- Now scroll down to “Types of data to script” and change it from schema only to Schema and Data.
- Click Ok. Click Next, Click Next. The script will now be created and generated in a new query window. Click Finish once it has completed. Below is a partial screenshot of the completed product.
As always, thanks for looking!
In my time as a Business Intelligence consultant and trainer I have picked up some pretty cool tricks and thought I would start blogging on these tips two or three times a week as I catch myself using them.
In this blog I am going to show you how you can set your default database when you connect to a server. I find this to be an extremely helpful little tip. Please see below.
- Open SSMS and from the object explorer click “Connect”.
- From the Connect to Server prompt: Enter your server and Authentication information.
- Click “Options”, located at the bottom right.
- Next click the “Connection Properties” tab found at the top.
- Locate “Connect to Database” and then click the drop down menu.
- From the dropdown menu select <Browse> and then select the database that you want to be your default. Click Connect..
- Voila! Now every time you connect to that server it will default to that database instead of master!
As always, thanks for looking!
Working with SSIS and the BI Stack from Microsoft I have discovered a few tips and tricks that come in quite handy. To my surprise a lot of these are not very well know in the BI World. In this series I am going to try and post one or two SSIS Tips and Tricks on a weekly basis.
As you are well aware the SELECT * syntax in SQL Server should not be used inside of SSIS. This is because the metadata in SSIS is very rigid and if you add or remove columns to the table in your select statement it can affect other transforms in the pipeline that have been defined with very specific metadata properties.
So if you are like many people who use SSIS it’s likely you alt + tab over to SQL Server Management Studios and then view the table and write your select syntax there with all the applicable columns for your query. Then you copy that syntax and alt + tab back over to BIDS / SSDTs and paste.
It’s unfortunate that there isn’t some kind of tool inside SSIS that will assist us with our incredibly difficult predicament. Just kidding, of course there is, if there wasn’t I wouldn’t be blogging about it! Let’s demonstrate.
First – Open up your OLE DB Source component in your data flow and write your Select * from table statement. For this example I used SELECT * FROM SALES.CUSTOMER in the AdventureWorks2012 database.
Next click “Build Query…” found on the right side of the OLE DB Source Editor.
Click ok and you are done! Thanks for looking and check back for more time saving tips and tricks.
I, like everyone, get an incredible amount of email on a daily basis. I recently learned some awesome tricks for searching my outlook that I wanted to share!
In the past when I wanted to search for something I would just type that item into the search box. For example ‘John Doe’. Unfortunately this returned a lot emails that John Doe not only might have sent me but also was cc’d or bcc’d in. It also appeared that if his name was in the subject that email would be returned. Well when you are working on a project in which multiple people are cc’d on every email this results in an overwhelming number of results.
So now to the good part!! Want to search for emails that you received from John Doe? Try this
From:John Doe (Note you don’t have to fully fill out his name.)
From:Joh – This will also return emails from John Doe, but of course anyone else with Joh as well.
Subject:Analytics (This will search the full subject string for the word ‘Analytics’
These are just a couple of the options available. For a full list please check out the website below:
Learn to narrow your search!