[PL] Konferencje SQL Server 2008 R2 Community Launch

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

SQL Server 2008 R2 Community Launch

Premiera SQL Server 2008 R2 zaplanowana jest na marzec, ale już teraz warto zobaczyć, jakie nowinki firma Microsoft przygotowała w “połówce” (R2 nosi numer wersji 10.50.XXXX).

Polska Grupa Użytkowników SQL Server (PLSSUG) szykuje serię konferencji pod szyldem SQL Server 2008 R2 Community Launch. W niektórych miastach, na przykład w Łodzi, konferencja będzie całodniowa, w innych, jak w Warszawie, będzie miała formę wieczornego spotkania. Uczestnictwo jest darmowe – wymagana jest oczywiście uprzednia rejestracja (do rejestracji wymagane jest założenie konta na portalu ms-groups.pl).

Kalendarz konferencji:

18.03 – Poznań
20.03 – Łódź
24.03 – Warszawa
30.03 – Gdańsk
30.03 – Lublin
08.04 – Wrocław

Serdecznie zapraszam.

PS. Będzie można mnie spotkać w Warszawie, Łodzi i Poznaniu. Moja prezentacja we wszystkich trzech miastach będzie miała tytuł: “Most wanted – czego oczekujemy od kolejnych wersji SQL Server”.

Witryna konferencji SQL Server 2008 R2 Community Launch

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[PL] Materiały z prezentacji "DMV od A do Z"

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Bardzo dziękuję tym, którzy dzisiaj cierpliwie wysłuchali (mimo późnej pory) mojej prezentacji “DMV od A do Z” w ramach 43. spotkania PLSSUG Warszawa. Mam nadzieję, że choć część zaprezentowanego kodu T-SQL będzie przydatna w codziennej pracy z SQL Serverem. Zgodnie z obietnicą publikuję na stronie zasobów materiały (skrypt) z mojej sesji.

PS. Gratulacje dla Pawła Krasowskiego za przełamanie wszelkich oporów i wewnętrznych obaw i zaprezentowanie sesji o hierarchiach, która wyzwoliła chęć do dyskusji (przynajmniej we mnie). Dobry początek, Pawle.

Pobierz materiały z prezentacji “DMV od A do Z” (SQL, 19 KB)

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[PL] Materiały z prezentacji "Typy danych w SQL Server 2008"

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Wczoraj poprowadziłem prezentację online pt. “Typy danych w SQL Server 2008” w ramach cyklu “SQL Server nie tylko dla orłów” organizowanego przez Polską Grupę Użytkowników SQL Server (PLSSUG) i portal VirtualStudy.pl. Bardzo dziękuję wszystkim, którzy wysłuchali mojej prezentacji i zadawali liczne ciekawe pytania. Mam nadzieję, że spotkanie było dla uczestników owocne. Materiały (prezentacja + skrypt demo) zamieściłem na stronie zasobów.

Przypominam, że już w środę, 3 marca, następne spotkanie z tej samej serii. Damian Widera (SQL Server MVP) będzie opowiadał o tworzeniu tabel i więzów. I jeszcze raz nadmienię, że organizatorzy i prelegenci czekają na wszelkie uwagi i komentarze (pytania?) na forum portalu VirtualStudy.pl. Prezentacji o SQL Server może być więcej, niż zaplanowaliśmy. Wystarczy, że będzie widoczna potrzeba zorganizowania sesji na określony temat.

Zapraszamy do czynnego udziału w spotkaniach i wymiany poglądów oraz doświadczeń na forum.

Pobierz materiały z prezentacji “Typy danych w SQL Server 2008” (ZIP, 305 KB)

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[EN] SQL Server – Don’t (sp_)rename your database objects

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Ok, so you have a typo in the name of your stored procedure (or any other procedural object in your SQL Server database). Or, maybe your stored procedure name does not fit the naming policy rules. Anyway, you want to change the name of this damn procedure immediately. The very first thought – use sp_rename system stored procedure (or simply press F2 while having the procedure selected in the Object Explorer window in SQL Server Management Studio). Stop! Do not rename your procedural objects!

And here is the reason why you should never ever use sp_rename.

Let’s create a dummy stored procedure in the tempdb system database:

USE tempdb;

GO

CREATE PROC dbo.SomeDummyProcedure

AS

GO

Now, let’s try to rename it:

EXEC sp_rename SomeDummyProcedure, SomeDummyProcedure_Renamed

Notice the warning message coming out:

Caution: Changing any part of an object name could break scripts and stored procedures.

Ok, now you know some objects can be broken. The job is done. Your procedure is renamed. Oh, really? Let’s see what is stored in sys.sql_modules catalog view:

SELECT *

FROM sys.sql_modules

WHERE [object_id] = OBJECT_ID('dbo.SomeDummyProcedure_Renamed');

The result is quite not what you would expect:

image

What the hell? The name of your procedure is changed but not its definition! It still contains the old name! Well, you may think that you should refresh the procedure:

EXEC sp_refreshsqlmodule 'dbo.SomeDummyProcedure_Renamed';

Again – a big surprise!

Msg 208, Level 16, State 6, Procedure sp_refreshsqlmodule_internal, Line 75
Invalid object name ‘dbo.SomeDummyProcedure’.

Quite interesting, huh? :-) It appears that sp_refreshsqlmodule stored procedure (used often to refresh views or to verify procedural objects during database migration) uses the object definition returned by sys.sql_modules catalog view. If you play for a while with some system objects you will find out that sp_helptext system stored procedure and OBJECT_DEFINITION system function (it’s used in sys.sql_modules to generate the definition column, and underneath there is an internal table sys.sysobjvalues that stores the object definitions as binaries) also return the definition with the old name of your procedure… What a shame. And – why am I not surprised? – this is by design. In Books Online they put some clarification:

Renaming a stored procedure, function, view, or trigger will not change the name of the corresponding object name in the definition column of the sys.sql_modules catalog view. Therefore, we recommend that sp_rename not be used to rename these object types. Instead, drop and re-create the object with its new name.

“But wait! There is this cool scripting option in the Management Studio tool!” – you could say. Well, yes, there is. But let’s look closer at what it does.

If you right-click the stored procedure in the Object Explorer or Object Explorer Details windows, you can script your procedure using Modify or Script Stored Procedure as options.

image

And, another surprise – both options return different T-SQL code!

-- This is what Modify option returns:
--------------------------------------

USE [tempdb]

GO

/****** Object:  StoredProcedure [dbo].[SomeDummyProcedure_Renamed]    Script Date: 02/02/2010 07:47:36 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROC [dbo].[SomeDummyProcedure_Renamed]

AS

-- And this is what Script Stored Procedure As option returns:
--------------------------------------------------------------

USE [tempdb]

GO

 

/****** Object:  StoredProcedure [dbo].[SomeDummyProcedure_Renamed]    Script Date: 02/02/2010 07:48:03 ******/

SET ANSI_NULLS ON

GO

 

SET QUOTED_IDENTIFIER ON

GO

 

ALTER PROC [dbo].[SomeDummyProcedure_Renamed]

AS

 

GO

Do not pay attention to the comments. Compare the procedure definitions in both cases. Do you see these blank lines? But also – notice that there is one more difference if you compare the above definitions to the original one. The square brackets! Where do they come from??? Of course, the code will run with no error, but THIS IS NOT THE ORIGINAL DEFINITION OF YOUR PROCEDURE!!! And what if you have some object versioning system? What if you rely on the previous version’s definition or its checksum? Then scripting any procedural object with Management Studio can make some problems.

And one more thing – when you script with Management Studio, notice that CREATE and ALTER keywords are always uppercase, even if they are lowercased in the original object definition.

So, my final remarks are the following:

  • do not ever use sp_rename to rename the procedural objects,
  • consider disallowing the executions of sp_rename in your databases (fortunately the RENAME event for DDL trigger is implemented in SQL Server 2008),
  • modify the T-SQL code returned by the scripting mechanism available in Management Studio if it’s critical to script object definition exactly as it was written when you created or lately altered the object.

If you agree with me that the way the scripting mechanism in Management Studio works is not good, see (and vote!) the following item on connect.microsoft.com:

SSMS: Scripting of procedural object changes object definition

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[PL] VirtualStudy.pl – dużo o SQL Server 2008 i PowerShell

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Już za dwa tygodnie, w poniedziałek 15 lutego, startuje nowa seria spotkań online zorganizowana wspólnie przez portal VirtualStudy.pl i Polską Grupę Użytkowników SQL Server (PLSSUG). Tym razem seria, pod wiele mówiącym tytułem – “SQL Server 2008 nie tylko dla orłów”, będzie przeznaczona dla osób, które chcą poznać od podstaw system Microsoft SQL Server 2008 i język Transact-SQL (poprzednia seria była ukierunkowana na przygotowanie do egzaminu 70-432). Jeżeli nie znasz Microsoft SQL Server, a chcesz go poznać i to w najnowszej odsłonie, zapraszam serdecznie. Będę jednym z prelegentów w tej serii (poprowadzę dwie prezentacje poświęcone typom danych w SQL Server 2008). Spotkania będą odbywały regularnie w poniedziałki. Jak zwykle wykorzystamy technologię Live Meeting. Wstęp jest całkowicie darmowy (wymagana jest jedynie rejestracja na portalu VirtualStudy.pl). Polecam.

A już za tydzień, 8 lutego, rozpocznie się inna, równie ciekawa seria – o PowerShell. Najpierw Grzegorz Tworek (Microsoft MVP – Enterprise Security) poprowadzi trzy prezentacje o tworzeniu skryptów PowerShell od podstaw po bardziej zaawansowane zagadnienia (WMI), a później lider poznańskiego oddziału PLSSUG – Łukasz Grala – poprowadzi dwie prezentacje o wykorzystaniu PowerShell w SQL Server 2008. Bezwzględnie warto to zobaczyć.

Reklama

Dodam jeszcze, że wszystkie prezentacje są nagrywane i udostępniane online na portalu VirtualStudy.pl. Zachęcam jednak do oglądania ich na żywo, bo wówczas można podjąć dyskusję z prelegentem i innymi uczestnikami spotkania.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[PL] SQLDay 2009 – wspomnień czar

VN:F [1.7.9_1023]
Rating: 5.0/5 (1 vote cast)

Pamiętacie jeszcze konferencję SQLDay 2009? Wrocławski oddział Polskiej Grupy Użytkowników SQL Server (PLSSUG) zorganizował wspaniałą imprezę, na której udało mi się wystąpić w roli prelegenta (wspólnie z Markiem Adamczukiem przedstawiłem prezentację na temat najlepszych praktyk w pracy z procedurami składowanymi).

Poniżej prezentuję film nagrany podczas konferencji (zmontowany oczywiście przez wrocławskich pasjonatów SQL Servera). Ech, to był dzień, jakich mało!

Get Microsoft Silverlight

A już niebawem szykujcie się na serię wydarzeń poświęconych SQL Server 2008 R2 w całej Polsce. Startujemy już w marcu!

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[PL] Chcesz zobaczyć świetną sesję z TechEd Europe 2009 (i to po polsku!)?

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Jeżeli na pytanie z tytułu tej notki odpowiesz sobie TAK, to koniecznie odwiedź portal VirtualStudy.pl. Już dziś wystartowała tam rejestracja na sesję online (w technologii Live Meeting), którą poprowadzi Paula Januszkiewicz, a która będzie zatytułowana Techniki hakerskie użyteczne dla administratora IT (oryginalny tytuł w języku angielskim: Useful Hacker Techniques: Which Part of HackersKnowledge Will Help You in Efficient IT Administration). Sesja ta cieszyła się ogromną popularnością podczas konferencji TechEd Europe 2009 w Berlinie. Dość rzec, że dwukrotnie zabrakło wówczas dla mnie miejsca w sali na około 300 osób…

Kilka informacji o Pauli: ekspert w dziedzinie bezpieczeństwa systemów, niedawno wyróżniona przez firmę Microsoft tytułem Most Valuable Professional (MVP) w kategorii Enterprise Security, założycielka grupy Women in Technology dla kobiet z branży IT i nie tylko, poczytna blogerka, prywatnie przemiła kobieta.

Myślę, że warto zarezerwować sobie poniedziałkowy (1 lutego 2010) wieczór od godziny 20:00 do późnych godzin nocnych (po sesji przewidziana jest debata na tematy: “Czy Administrator powinien mieć pojęcie o bezpieczeństwie?” oraz “Social Networking – dlaczego udostępniamy swoją tożsamość w sieci i co się z tym wiąże?”. Zapowiada się bardzo ciekawie.

Kliknij, by zarejestrować się na spotkanie (trzeba założyć konto na portalu VirtualStudy.pl)

*** Aby uczestniczyć w sesji, należy wcześniej pobrać i zainstalować klienta Live Meeting ***

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[EN] SQL Server – An index on a computed column does not prevent computations

VN:F [1.7.9_1023]
Rating: 4.0/5 (1 vote cast)

Last month I observed an interesting behavior of the query optimizer in SQL Server 2008 (this probably can be observed on the previous versions too). The example runs on the AdventureWorks2008 sample database. Consider the following query:

USE AdventureWorks2008;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

If you look at the execution plan it looks like this:

image 

Well, at first it may seem to be not very interesting. But if you look at the name of the nonclustered index scanned (IX_Customer_TerritoryID index from Sales.Customer table) you may start to wonder: why this individual index was used here? The index has the TerritoryID column as a key, and of course it also contains the CusomerID column since this is a clustered index key. Now, if you notice that the AccountNumber column is computed from CustomerID, then it’s easy to justify the optimizer’s choice (probably IX_Customer_TerritoryID is the smallest index that can be scanned to get all the necessary data from Sales.Customer table in this particular query). But wait! There is an index on the AccountNumber computed column! Why the hell it was not used in this case? Well, let’s try some hint here:

USE AdventureWorks2008;

GO

SET STATISTICS IO ON;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

SELECT

  h.SalesOrderID,

  h.OrderDate,

  c.CustomerID,

  c.AccountNumber

FROM Sales.Customer AS c WITH (INDEX(AK_Customer_AccountNumber))

INNER JOIN Sales.SalesOrderHeader AS h

ON c.CustomerID = h.CustomerID;

GO

SET STATISTICS IO OFF;

GO

According to the I/O statistics the second query (the one with INDEX hint) reads more pages from the Sales.Customer table than the first query. The cost of both queries is 50% (see below).

image

Looks like a nice sample of the cost-based optimization, doesn’t it? So, even when your computed column is indexed, you can expect the computations to be made anyway in some cases.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[EN] Code Library

VN:F [1.7.9_1023]
Rating: 4.0/5 (1 vote cast)

I’ve just added the Code Library page to my blog. I will put some scripts that I think are useful and/or interesting. The first script you can find there already is a piece of T-SQL code to retrieve some information about database files.

I hope some of the source codes will fit your needs.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live

[EN] Call for voting – ALTER TYPE in SQL Server

VN:F [1.7.9_1023]
Rating: 0.0/5 (0 votes cast)

Have you ever used an alias type in SQL Server? I bet you have. It’s really cool that you can create your own alias type with CREATE TYPE statement in your database and then use it in your database objects. What drives people to using the alias types is a thought that these types can be easily changed by a single operation which does not require looking into every individual database object and checking whether the alias type is used or not. Well, is this really the way it is? Unfortunately not.

There is no ALTER TYPE statement in SQL Server. So whenever you want to change your own alias type (for example to make it longer in case of variable length character types) you have to perform quite a lot of operations, like:

  • script and drop (or alter to make independent of the “altered” alias type) all procedural objects that use the “altered” alias type,
  • script and drop all constraints on columns of the “altered” alias type,
  • script and drop all foreign key referencing the columns mentioned above,
  • rename the “altered” alias type,
  • create the new alias type with the new definition and the old name of the “altered” alias type,
  • alter all columns of the “old type” to make them using the new alias type,
  • recreate all dropped objects and constraints,
  • refresh just recreated procedural objects.

That doesn’t look simple, does it? The bad news is that this is not all – you should perform all those operations in a single transaction… The reason is quite obvious – you are going to do some nasty things with the database objects (drops, alters, recreates). It would be bad if the process stopped somewhere in the middle (leaving some objects not restored to their original definitions). So, there is plenty of T-SQL code to write, all with transaction and error handling, dynamic T-SQL, lurking into metadata and so forth.

Unfortunately, there is a bug making all the operation practically impossible to perform in a single transaction in certain scenarios (when you use a table variable with a column of the “altered” alias type). See this item for details:
Deadlock occurs when creating user-defined data type and objects that use it

They promised to fix it in SQL Server 2008 R2. Just can’t wait to check it out (for now it’s not fixed in CTP).

My final point is to encourage you to voting for the item: MSFT-MSO: Support ALTER TYPE. This (ALTER TYPE statement) is something that I really wish to see in the next release of SQL Server. So please, vote for this item to be fixed/implemented. Let me know if you vote. Thanks in advance!

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Technorati
  • Twitter
  • Wykop
  • LinkedIn
  • Live