It has been some time since I have written one of my SQL Tip blogs. I like to use the “Edit Top 200” rows functionality provided by SSMS when making quick but different updates across like records in SQL Server. Did you know you can edit the top 200 rows query and get the records you’re interested in updating? We can do this in just a few easy steps.
First open up the “Edit Top 200 Rows” window in SSMS for the table you want to edit.
Second, Right click at the top left of the table and from the drop down list select Pane > SQL.
Next, now we see a SQL statement that we can edit. Here I simply added the where clause WHERE MakeFlag = ‘TRUE’
Once the SQL has been updated it needs to be executed. Right click on the top left corner of the table again. This time select “Execute SQL”.
Below you can see the new result set available now for editing!
As always thanks for looking.
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!