Notes for 11/28 Talk - SMO and INFORMATION_SCHEMA - Jon Galloway

Notes for 11/28 Talk - SMO and INFORMATION_SCHEMA

I spoke at the San Diego .NET User Group meetin on 11/28 on SQL Server Metadata (SMO and INFORMATION_SCHEMA). The complete notes should be available on the user group downloads page, but here are the rough notes:

Extract of the PowerPoint outline:

 

Here's my PowerSMO (SMO in PowerShell) script:

#POWERSMO DEMO
#USES POWERSMO -
http://www.pluralsight.com/dan/samples/PowerSMO.zip

#SETUP VOODOO
$executionPolicy = get-ExecutionPolicy
set-ExecutionPolicy "Unrestricted"
.\InitPowerSMO.ps1
cls

#CONNECT TO DATABASE
$server = SMO_Server "(local)\SQL2005"
$server.ConnectionContext.SqlExecutionModes = 3 #ExecuteAndCaptureSql
$database = $server.Databases["AdventureWorks"]
$database.FileGroups[0].Files[0].FileName

#LIST TABLES
$database.Tables | %{$_.name}

#CREATE A NEW TABLE
$orders = SMO_Table $database "Orders"
$order_number = SMO_Column $orders "Order Number" (SMO_DataType "Int")
$orders.Columns.Add($order_number)
$customer_name = SMO_Column $orders "Customer Name" (SMO_DataType "Varchar")
$orders.Columns.Add($customer_name)
$value = SMO_Column $orders "Value" (SMO_DataType "Int")
$orders.Columns.Add($value)
$orders.Create()

#SHOW SCHEMA
$orders.Columns | format-Table Name, DataType -auto
$orders.Script()

#CHANGE SOME COLUMNS
$orders.Columns["Value"].DataType = (SMO_DataType "Money")
$orders.Alter()
$orders.Script()

#DROP A COLUMN, THEN THE TABLE
$orders.Columns["Customer Name"].Drop()
$orders.Drop()

cls
$server.ConnectionContext.CapturedSql.Text
#CLEANUP
$server = ''
set-ExecutionPolicy -executionPolicy $executionPolicy

 

Here's the code from my winform sample

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

namespace SMO_Overview
{
public partial class Main : Form
{
Database db;

public Main()
{
InitializeComponent();
}

private void btnConnect_Click(object sender, EventArgs e)
{
Cursor.Current
= Cursors.WaitCursor;
GetTables(connectionTextbox1.SqlConnectionString);
Cursor.Current
= Cursors.Default;
}

private void GetTables(string connectionString)
{
ddlTables.Items.Clear();
SqlConnection connection
= new SqlConnection(connectionString);
Server server
= new Server(new ServerConnection(connection));
db
= server.Databases[connection.Database];

foreach (Table table in db.Tables)
{
if (!table.IsSystemObject)
{
if(!string.IsNullOrEmpty(table.Schema))
ddlTables.Items.Add(table.Schema
+ "." + table.Name);
else
ddlTables.Items.Add(table.Name);
}
}
if (ddlTables.Items.Count > 0)
ddlTables.SelectedIndex
= 0;
}

private void ddlTables_SelectedIndexChanged(object sender, EventArgs e)
{
Cursor.Current
= Cursors.WaitCursor;
try
{
if (ddlTables.SelectedIndex >= 0)
{
string[] tableSelection = ddlTables.Text.Split('.');
Table table
= db.Tables[tableSelection[1],tableSelection[0]];
DataTable columnList
= new DataTable();
columnList.Columns.Add(
"Column");
columnList.Columns.Add(
"Datatype");

foreach (Column column in table.Columns)
{
DataRow row
= columnList.NewRow();
row[
"Column"] = column.Name;
row[
"Datatype"] = SmoUtil.GetDatatypeString(column);
columnList.Rows.Add(row);
}
dgvColumns.DataSource
= columnList;
}
}
catch { }
Cursor.Current
= Cursors.Default;
}
}
}

I previously posted most of the INFORMATION_SCHEMA SQL Scripts: Some of my favorite INFORMATION_SCHEMA utility queries

Thanks to Justin Angel, who sent me hundreds of slides about SQL Server 2005 for his upcoming talk on December 4th at the Israeli SQL Server Usergroup. I'm sorry I won't be able to see his talk, it looks like it will be incredible.

Published Sunday, December 03, 2006 12:26 AM by Jon Galloway
Filed under: ,

Comments

# re: Notes for 11/28 Talk - SMO and INFORMATION_SCHEMA

Hey Jon,

Glad to help.

The SMO powershell code is extremely useful, thanks!

Thursday, December 07, 2006 12:31 PM by Justin-Josef Angel [MVP]

# Tips for a Technical Presentation

I spoke at the local .NET user group meeting last week. I've done my share of software demos and short

Friday, September 28, 2007 4:07 PM by Jon Galloway

# re: Notes for 11/28 Talk - SMO and INFORMATION_SCHEMA

Hello there, just became aware of your blog through Google, and

found that it is truly informative. I'm gonna watch out for brussels. I'll appreciate

if you continue this in future. Numerous people will be benefited from your writing.

Cheers!

Saturday, December 08, 2012 2:22 PM by Weed

# re: Notes for 11/28 Talk - SMO and INFORMATION_SCHEMA

By WebOsPublisher

First off,i would like to thank guesprime for handing leadership down to me,but there are many problems within our union. Many are easy

HELP WANTED (wanna help, come here to see what this union needs done!) - GameSpot.com--

#site_nav div.custom_site_subnav background: #48adde;width:160px; overflow:hidden;#site_nav ul.custom_site_subnav float:left; margin:-1px 0 -110px; padding:0 0 110px; width:100%;#site_nav a.custom_nav_action max-width:50px; overflow:hidden;#site_nav li.custom_masthead_item span max-width:60px;#site_nav li.custom_masthead_item max-width:60px; padding-right:5px;#site_nav .dropdown_open .custom_dropdown_wrap  padding: 2px 0 0; margin: -1px 0 0 ;background: none repeat scroll 0 0 transparent;border-style:solid; border-width:1px; border-top-color: #5fd5fb;border-left-color: #5fd5fb;border-right-color: #3488ba;border-bottom-color: #3488ba;#site_nav img.custom_masthead_image  width:45px; height:56px; margin:-20px 0 -20px -8px; #site_nav .dropdown_open .custom_dropdown background: #48adde; repeat scroll 0 0 transparent !important;#site_masthead .dropdown_open .custom_dropdown -moz-box-shadow: none !important; box-shadow: none !important; -webkit-box-shadow: none !important#site_masthead .active .custom_action_wrap, #site_masthead .dropdown_open .custom_action_wrap background:no-repeat scroll transparent !important;#site_masthead .custom_masthead_image -moz-box-shadow: none !important; box-shadow: none !important; -webkit-box-shadow: none !important#site_nav a.custom_nav_image float:none !important;#site_nav li.custom_subnav_item display:inline; float:left;border-top:1px solid #ffffff;font-size:11px; line-height:14px; width:100%;#site_nav a.custom_subnav_action  background: #48adde no-repeat;color:#ffffff;display:block; font-weight:normal; padding:5px 15px; text-decoration:none;#site_nav a.custom_subnav_action:hover background-color: #48adde;color: #000000;

GameSpot

 SearchSearchSearch  

Sign on Options

Log in »

sign in

Email

Password

Forgot Password?

Sign up

Main Nav

Best of 2012 Peoples' Choice Voting  

 Reviews  

Latest Reviews

All Reviews

Video Reviews

Reviews Blog

Reviews on Metacritic

 News  

Top Stories

News Blog

Rumor Blog

Daily Updates

New Releases

 Videos  

All Videos

GameSpot Live

On The Spot

Start/Select

Plays Like

Now Playing

Video Reviews

Video Previews

Trailers

Gameplay

Interviews

 Cheats  

Popular Game Cheats

GameSpot Walkthroughs

Walkthroughs on GameFAQs

Platform Nav

 Xbox 360  

Xbox 360 Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

Cheats $ Walkthroughs

Xbox Live

 PC  

PC Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

Cheats $ Walkthroughs

Downloads

 PS3  

PS3 Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

Cheats $ Walkthroughs

PlayStation Network

 Wii U  

Wii U Home

Wii Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

 3DS  

3DS Home

DS Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

Cheats $ Walkthroughs

 PS Vita  

PS Vita Home

PSP Home

Reviews

Previews

New Releases

Top Games

All Games

Videos

Cheats $ Walkthroughs

 iPhone  

iPhone Home

Highest Rated

Most Popular

Plays Like

Reviews

iPhone App

 Android  

Android Home

Highest Rated

Most Popular

Plays Like

Community Nav

 Forums  

GameSpot Forums

Forum Search

Community Blog

 Fuse  

What's Hot

 eSports  

 Watch GameSpot on Youtube  Follow @GameSpot

 Theme: [Light Selected] To Dark»

Forums

 ›

 The Contra Alliance (union board)

   ›

 HELP WANTED (wanna help, come here to se ...  

  HELP WANTED (wanna help, come here to see what this union needs done!)

   Search ForumsSearchForum ActionsNew MessageTag Favorites_____________Edit FavoritesAdd to Favorites_____________  

Quick Messagefalconclan Level 41Thunder ForcePosts: 16658Mar 8, 2006 3:53 pm GMTFirst off, i would like to thank guesprime for handing leadership down to me, but there are many problems within our union. Many are easy fixes, and some are harder, more time consuming ones.To start, we are at union status "AWOL" thats basicly a signal to abandon ship for some! BUT DONT DO THAT. freaking out will just make that rating worse. It shouldnt be hard to get out of this, but we need more posting activity and recruiters to find people who are willing to join and post. I dont want to just spam countless gs mailboxes, since no one will respect our pleas if we do that.Again we need people posting, but we also need to get our union noticed. since we have no signature icons or anything it'll be hard. those of you with knowledge of making signatures, we'd be greatly pleased if you helped out with those, but if you can't make sigs, simply put a link in your signature.add anything else you think would be good for the union if you'd like...-- falconFirst off, i would like to thank guesprime for handing leadership down to me, but there are many problems within our union. Many are easy fixes, and some are harder, more time consuming ones.To start, we are at union status "AWOL" thats basicly a signal to abandon ship for some! BUT DONT DO THAT. freaking out will just make that rating worse. It shouldnt be hard to get out of this, but we need more posting activity and recruiters to find people who are willing to join and post. I dont want to just spam countless gs mailboxes, since no one will respect our pleas if we do that.Again we need people posting, but we also need to get our union noticed. since we have no signature icons or anything it'll be hard. those of you with knowledge of making signatures, we'd be greatly pleased if you helped out with those, but if you can't make sigs, simply put a link in your signature.add anything else you think would be good for the union if you'd like...-- falconReport AbuseQuoteReplyPlease wait. Quick reply will be available shortly.Quick QuoteQuick Replypropyro Level 19Gitaroo ManPosts: 6758Mar 8, 2006 10:22 pm GMTwhut?  yea i'll try.Metroid whut?

:roll:  yea i'll try.Report AbuseQuoteReplyPlease wait. Quick reply will be available shortly.Quick QuoteQuick Replyboricua4life21 Level 8Quad DamagePosts: 88Mar 11, 2006 4:05 pm GMTi posted a topic about us in the Union Recruitment forum, so hopefully some more people will notice us and join... i posted a topic about us in the Union Recruitment forum, so hopefully some more people will notice us and join...Report AbuseQuoteReplyPlease wait. Quick reply will be available shortly.Quick QuoteQuick Replyfalconclan Level 41Thunder ForcePosts: 16658Mar 11, 2006 8:38 pm GMT boricua4life21 wrote: i posted a topic about us in the Union Recruitment forum, so hopefully some more people will notice us and join...i posted in it... The problem is, recruiting doesnt work anymore, due to spammers. Most people dont even look at requests anymore... Thats why i posted in a few unions i knew well, and it worked

[QUOTE="boricua4life21"]i posted a topic about us in the Union Recruitment forum, so hopefully some more people will notice us and join...[/QUOTE]i posted in it... The problem is, recruiting doesnt work anymore, due to spammers. Most people dont even look at requests anymore... Thats why i posted in a few unions i knew well, and it worked :)Report AbuseQuoteReplyPlease wait. Quick reply will be available shortly.Quick QuoteQuick Reply  Search ForumsSearchForum ActionsNew Message

Forums

 ›

 The Contra Alliance (union board)

   ›

 HELP WANTED (wanna help, come here to se ...  

GameSpot

SearchSearchSearchRSSHomePCXbox 360Wii UPS3PS VitaPSP3DSDSiPhoneMobileForumsVideosCheatsNew ReleasesDownloadsNewsWorldwideAbout UsJoin GameSpotHelpAdvertise on GameSpotUK.GameSpot.comGameFAQs.comGameRankings.comMetacritic.comGiantBomb.com

What's Hot:GameSpot's Best of 2012 AwardsThe Phantom Pain revealedDark Souls 2 on the wayTop Games:Skyrim - Dragonborn (X360)Halo 4 (X360)League of Legends (PC)Far Cry 3 (X360)SpyParty (PC)Far Cry 3 (PC)Far Cry 3 (PS3)Elder Scrolls V: Skyrim (X360)Top Cheats:Medieval II: Total War CheatsSuper Smash Bros. Melee CheatsDragon Ball Z: Budokai 3 CheatsYu-Gi-Oh! GX: Duel Academy CheatsGTA: San Andreas CheatsHalo 4 CheatsCounter-Strike: Condition Zero CheatsYu-Gi-Oh! Ultimate CheatsGameSpot On:TwitterFacebookYouTubeGoogle+Mobile

Visit other CBS Interactive Sites

Select Site

BNET

CBS Cares

CBS College Sports

CBS Films

CBS Radio

CBS.com

CBSInteractive

CBSNews.com

CBSSports.com

CHOW

CNET

Find Articles

GameSpot

Help.com

Last.fm

MaxPreps

Metacritic.com

Moneywatch

MovieTome

MP3.com

mySimon

NCAA

Radio.com

Search.com

Shopper.com

Showtime

SmartPlanet

TechRepublic

The Insider

TV.com

UrbanBaby.com

ZDNet

BNET

CBS Cares

CBS College Sports

CBS Films

CBS Radio

CBS.com

CBSInteractive

CBSNews.com

CBSSports.com

CHOW

CNET

Find Articles

GameSpot

Help.com

Last.fm

MaxPreps

Metacritic.com

Moneywatch

MovieTome

MP3.com

mySimon

NCAA

Radio.com

Search.com

Shopper.com

Showtime

SmartPlanet

TechRepublic

The Insider

TV.com

UrbanBaby.com

ZDNet

About CBS Interactive | Jobs | Advertise

© 2012 CBS Interactive Inc. All rights reserved. | Privacy Policy (UPDATED) | Ad Choice | Terms of Use

window.fbAsyncInit = function()  false;

if (FB)

FB._https = true;         FB.init(

appId: 91756522905,

status: false,             xfbml: true );

var queue = window.fbCallbackQueue

;

Asset.javascript('//connect.facebook.net/en_US/all.js', id: 'facebook-jssdk', async: true);

var om = "is_dev":0,"context":"forum_board":"the contra alliance (union board)","forum_topic":"help wanted (wanna help, come here to see what this union needs done!)","page_type":"forum topic","platform":"platform agnostic","sections":"forums";

for(var key in om_dynamic_vars)

om.context[key] = om_dynamic_vars[key];

Asset.javascript('/js/tracking/omniture/s_code.min.js');

id.lenta.ru/.../108850

Tuesday, December 11, 2012 4:28 AM by app-bits.lcm

Leave a Comment

(required) 
(required) 
(optional)
(required)