Saturday 19 August 2017

Moving average ssas


Kebanyakan orang sudah familiar dengan ungkapan, quotthis ini akan membunuh dua burung dengan satu stonequot. Jika tidak, fase mengacu pada pendekatan yang membahas dua tujuan dalam satu tindakan. (Sayangnya, ungkapan itu sendiri agak tidak menyenangkan, karena kebanyakan dari kita tidak ingin melempar batu pada hewan yang tidak berdosa) Hari ini saya akan membahas beberapa hal mendasar mengenai dua fitur hebat di SQL Server: indeks Columnstore (hanya tersedia di SQL Server Enterprise) dan SQL Query Store. Microsoft benar-benar menerapkan indeks Columnstore di SQL 2012 Enterprise, meskipun telah menyempurnakannya dalam dua rilis terakhir dari SQL Server. Microsoft memperkenalkan Query Store di SQL Server 2016. Jadi, apa saja fitur ini dan mengapa mereka penting Nah, saya punya demo yang akan mengenalkan kedua fitur tersebut dan menunjukkan bagaimana mereka dapat membantu kita. Sebelum saya melangkah lebih jauh, saya juga membahas fitur ini (dan fitur SQL 2016 lainnya) di artikel Majalah KODE saya tentang fitur baru SQL 2016. Sebagai pengantar dasar, indeks Columnstore dapat membantu mempercepat kueri yang memindai berdasarkan data dalam jumlah besar, dan Query Query melacak eksekusi query, rencana eksekusi, dan statistik runtime yang biasanya perlu Anda kumpulkan secara manual. Percayalah ketika saya mengatakannya, ini adalah fitur hebat. Untuk demo ini, saya akan menggunakan database demo Data Warehouse Microsoft Contoso. Ngomong ngomong, Contoso DW seperti kuota AdventureWorksquot yang sangat besar, dengan tabel berisi jutaan baris. (Tabel AdventureWorks terbesar berisi sekitar 100.000 baris paling banyak). Anda bisa mendownload database Contoso DW disini: microsoften-usdownloaddetails. aspxid18279. Contoso DW bekerja sangat baik saat Anda ingin menguji kinerja pada pertanyaan melawan tabel yang lebih besar. Contoso DW berisi tabel data warehouse standar yang disebut FactOnLineSales, dengan 12,6 juta baris. Itu tentu bukan tabel gudang data terbesar di dunia, tapi juga permainan anak-anak. Misalkan saya ingin meringkas jumlah penjualan produk untuk tahun 2009, dan memberi peringkat produk. Saya mungkin menanyakan tabel fakta dan bergabung ke tabel Dimensi Produk dan menggunakan fungsi RANK, seperti: Berikut adalah hasil parsial dari 10 baris teratas, oleh Total Sales. Di laptop saya (i7, 16 GB RAM), permintaan membutuhkan waktu 3-4 detik untuk dijalankan. Itu mungkin tidak tampak seperti akhir dunia, namun beberapa pengguna mungkin mengharapkan hasil hampir instan (seperti yang mungkin Anda lihat seketika saat menggunakan Excel dari kubus OLAP). Satu-satunya indeks yang saya miliki saat ini di tabel ini adalah indeks berkerumun pada kunci penjualan. Jika saya melihat rencana eksekusi, SQL Server membuat sebuah saran untuk menambahkan indeks penutup ke tabel: Sekarang, hanya karena SQL Server menyarankan sebuah indeks, tidak berarti Anda harus secara membabi buta membuat indeks pada setiap pesan kuota indeks kuota. Namun, dalam hal ini, SQL Server mendeteksi bahwa kita memfilter berdasarkan tahun, dan menggunakan Product Key dan Sales Amount. Jadi, SQL Server menyarankan indeks penutup, dengan DateKey sebagai bidang indeks kunci. Alasan kami menyebutnya indeks quotcoveringquot adalah karena SQL Server akan melakukan kuota sepanjang fieldquot non-key yang kami gunakan dalam query, quotfor the ridequot. Dengan cara itu, SQL Server tidak perlu menggunakan tabel atau indeks berkerumun di semua mesin database hanya dengan menggunakan indeks pengaitan untuk kueri. Meliputi indeks sangat populer di data pergudangan dan pelaporan database skenario tertentu, meskipun harganya terjangkau oleh mesin database. Catatan: Meliputi indeks telah ada sejak lama, jadi saya belum membuka indeks Columnstore dan Query Store. Jadi, saya akan menambahkan indeks penutupnya: Jika saya menjalankan kueri yang sama dengan saya, saya berlari beberapa saat yang lalu (yang mengumpulkan jumlah penjualan untuk setiap produk), kueri kadang tampaknya berjalan sekitar satu detik lebih cepat, dan saya mendapatkan Rencana eksekusi yang berbeda, yang menggunakan Indeks Seek dan bukan Index Scan (dengan menggunakan tombol tanggal pada indeks penutup untuk mengambil penjualan untuk tahun 2009). Jadi, sebelum Indeks Columnstore, ini bisa menjadi salah satu cara untuk mengoptimalkan kueri ini di banyak versi SQL Server yang lebih lama. Ini berjalan sedikit lebih cepat daripada yang pertama, dan saya mendapatkan rencana eksekusi dengan Index Seek daripada Index Scan. Namun, ada beberapa masalah: Dua operator eksekusi quotIndex Seekquot dan quotHash Match (Aggregate) mengutip keduanya pada dasarnya mengoperasikan quotrow oleh rowquot. Bayangkan ini dalam sebuah tabel dengan ratusan juta baris. Terkait, pikirkan isi tabel fakta: dalam kasus ini, satu nilai kunci tanggal dan atau satu nilai kunci produk dapat diulang di ratusan ribu baris (ingat, tabel fakta juga memiliki kunci untuk geografi, promosi, salesman , Dll.) Jadi, ketika quotIndex Seekquot dan quotHash Matchquot bekerja baris demi baris, mereka melakukannya atas nilai yang mungkin diulang di banyak baris lainnya. Ini biasanya terjadi di segelintir indeks SQL Server Columnstore, yang menawarkan skenario untuk meningkatkan kinerja kueri ini dengan cara yang menakjubkan. Tapi sebelum saya melakukannya, mari kita kembali ke masa lalu. Mari kembali ke tahun 2010, saat Microsoft memperkenalkan add-in untuk Excel yang dikenal sebagai PowerPivot. Banyak orang mungkin ingat melihat demo PowerPivot for Excel, di mana pengguna bisa membaca jutaan baris dari sumber data luar ke Excel. PowerPivot akan memampatkan data, dan menyediakan mesin untuk membuat Tabel Pivot dan Diagram Pivot yang tampil dengan kecepatan luar biasa terhadap data yang dikompres. PowerPivot menggunakan teknologi in-memory yang disebut Microsoft quotVertiPaqquot. Teknologi in-memory di PowerPivot pada dasarnya akan mengambil nilai kunci bisnis duplikat kunci utama dan memampatkannya ke satu vektor tunggal. Teknologi in-memory juga akan memilah-milah nilai-nilai ini secara paralel, dalam blok beberapa ratus sekaligus. Intinya adalah Microsoft memanggang sejumlah besar penyempurnaan kinerja ke dalam fitur memori VertiPaq yang bisa kita gunakan, langsung dari kotak pepatah. Mengapa saya mengambil jalan kecil ini menyusuri jalur memori Karena di SQL Server 2012, Microsoft menerapkan salah satu fitur terpenting dalam sejarah mesin database mereka: indeks Columnstore. Indeks benar-benar sebuah indeks hanya dalam nama: ini adalah cara untuk mengambil tabel SQL Server dan membuat kolom kolom terkompresi dalam memori yang memampatkan nilai kunci asing duplikat ke nilai vektor tunggal. Microsoft juga menciptakan kolam penyangga baru untuk membaca nilai vektor terkompresi ini secara paralel, menciptakan potensi peningkatan kinerja yang sangat besar. Jadi, saya akan membuat indeks kolom di atas meja, dan saya akan melihat seberapa jauh lebih baik (dan lebih efisien) kueri berjalan, versus kueri yang berjalan melawan indeks penutup. Jadi, saya akan membuat salinan duplikat FactOnlineSales (saya akan menamakannya FactOnlineSalesDetailNCCS), dan saya akan membuat indeks kolom di tabel duplikat sehingga saya tidak akan mengganggu tabel asli dan indeks penutupan dengan cara apa pun. Selanjutnya, saya akan membuat indeks kolom di tabel baru: Perhatikan beberapa hal: Saya telah menetapkan beberapa kolom kunci asing, serta Angka Penjualan. Ingatlah bahwa indeks kolom tidak seperti indeks toko-toko tradisional. Tidak ada quotkeyquot. Kami hanya menunjukkan kolom mana yang harus dikompres SQL Server dan ditempatkan di gudang data dalam memori. Untuk menggunakan analogi PowerPivot untuk Excel saat kita membuat indeks kolom, kita akan memberitahu SQL Server untuk melakukan hal yang sama seperti yang dilakukan PowerPivot saat kita mengimpor 20 juta baris ke Excel menggunakan PowerPivot Jadi, saya akan menjalankan kembali kueri, kali ini menggunakan Tabel factOnlineSalesDetailNCCS yang digandakan yang berisi indeks kolomstore. Permintaan ini berjalan seketika dalam waktu kurang dari satu detik. Dan saya juga bisa mengatakan bahwa meskipun tabel itu memiliki ratusan juta baris, buku itu tetap akan terbentang dari kutipan bulu mata yang pepatah. Kita bisa melihat rencana eksekusi (dan dalam beberapa saat, kita akan melakukannya), tapi sekarang saatnya meliput fitur Query Store. Bayangkan sejenak, bahwa kami menjalankan kedua pertanyaan semalam: kueri yang menggunakan tabel FactOnlineSales biasa (dengan indeks penutup) dan kemudian kueri yang menggunakan tabel duplikat dengan indeks Columnstore. Saat kita masuk keesokan paginya, kami ingin melihat rencana eksekusi untuk kedua pertanyaan saat mereka berlangsung, begitu pula dengan statistik eksekusi. Dengan kata lain, kami ingin melihat statistik yang sama bahwa kami dapat melihat apakah kami menjalankan kedua kueri secara interaktif di SQL Management Studio, menyerahkan TIME dan IO Statistics, dan melihat rencana eksekusi tepat setelah menjalankan kueri. Nah, itulah yang dilakukan oleh Toko Kueri agar kita dapat mengaktifkan (enable) Query Store untuk database, yang akan memicu SQL Server untuk menyimpan eksekusi query dan merencanakan statistik sehingga kita dapat melihatnya nanti. Jadi, saya akan mengaktifkan Query Store di database Contoso dengan perintah berikut (dan saya juga akan menghapus semua caching): Kemudian saya akan menjalankan dua query (dan quotpretendquot yang saya jalankan beberapa jam yang lalu): Sekarang mari kita berpura-pura berlari berjam-jam. Lalu. Menurut apa yang saya katakan, Query Store akan menangkap statistik eksekusi. Jadi bagaimana cara melihatnya Untungnya, itu cukup mudah. Jika saya memperluas basis data Contoso DW, saya akan melihat folder Query Store. Toko Kueri memiliki fungsionalitas yang luar biasa dan saya akan mencoba meliputnya dalam entri blog berikutnya. Tapi untuk saat ini, saya ingin melihat statistik eksekusi pada dua query, dan secara khusus memeriksa operator eksekusi untuk indeks kolomstore. Jadi, saya akan mengklik kanan pada Kuasa Mengonsumsi Sumber Daya Teratas dan menjalankan opsi itu. Itu memberi saya bagan seperti di bawah ini, di mana saya bisa melihat durasi eksekusi (dalam milidetik) untuk semua pertanyaan yang telah dieksekusi. Dalam contoh ini, Query 1 adalah query terhadap tabel asli dengan indeks penutup, dan Query 2 melawan tabel dengan indeks kolomstore. Angka tersebut tidak terletak pada indeks kolom kerja mengungguli indeks tablecovering asli dengan faktor hampir 7 banding 1. Saya dapat mengubah metrik untuk melihat konsumsi memori. Dalam kasus ini, perhatikan bahwa query 2 (query indeks kolomstore) menggunakan lebih banyak memori. Ini menunjukkan dengan jelas mengapa indeks columnstore mewakili teknologi kuotasi-memoriquot SQL Server memuat seluruh indeks kolom di memori, dan menggunakan kolam penyangga yang sama sekali berbeda dengan operator eksekusi yang ditingkatkan untuk memproses indeks. OK, jadi kita punya beberapa grafik untuk melihat statistik eksekusi kita bisa melihat rencana eksekusi (dan eksekusi operator) yang terkait dengan setiap eksekusi Ya, kita bisa Jika Anda klik pada baris vertikal untuk query yang menggunakan indeks kolomstore, Anda akan melihat eksekusi Rencanakan di bawah ini Hal pertama yang kita lihat adalah bahwa SQL Server melakukan pemindaian indeks kolom, dan itu mewakili hampir 100 dari biaya kueri. Anda mungkin berkata, quotWait sebentar, kueri pertama menggunakan indeks penutup dan melakukan pencarian indeks jadi bagaimana pemindaian indeks kolom bisa lebih cepat. Pertanyaan yang sah, dan untungnya ada sebuah jawaban. Bahkan ketika query pertama melakukan pencarian indeks, ia masih mengeksekusi quotrow oleh rowquot. Jika saya meletakkan mouse di atas operator pemindai indeks kolom, saya melihat tooltip (seperti yang ada di bawah), dengan satu pengaturan penting: Mode Eksekusi adalah BATCH (berlawanan dengan ROW), yaitu apa yang kami lakukan dengan kueri pertama yang menggunakan Meliputi indeks). Mode BATCH mengatakan bahwa SQL Server sedang memproses vektor terkompresi (untuk nilai kunci asing yang diduplikasi, seperti kunci produk dan kunci tanggal) dalam jumlah hampir 1.000, secara paralel. Jadi SQL Server masih bisa mengolah indeks columnstore jauh lebih efisien. Selain itu, jika saya menempatkan mouse di atas tugas Hash Match (Aggregate), saya juga melihat bahwa SQL Server mengumpulkan indeks kolom menggunakan mode Batch (walaupun operator itu sendiri mewakili persentase kecil dari biaya kueri) Akhirnya, Anda Mungkin bertanya, quotOK, jadi SQL Server memampatkan nilai dalam data, memperlakukan nilai sebagai vektor, dan membacanya di blok hampir seribu nilai secara paralel namun kueri saya hanya menginginkan data untuk tahun 2009. Begitu juga pemindaian SQL Server atas Seluruh rangkaian dataquot Sekali lagi, sebuah pertanyaan bagus. Jawabannya adalah, quotNot reallyquot. Untungnya bagi kami, pool buffer index kolom baru melakukan fungsi lain yang disebut quotmentment eliminationquot. Pada dasarnya, SQL Server akan memeriksa nilai vektor untuk kolom kunci tanggal di indeks kolomstore, dan menghilangkan segmen yang berada di luar cakupan tahun 2009. Saya akan berhenti di sini. Dalam posting blog berikutnya, saya akan membahas indeks kolom dan Query Store secara lebih rinci. Intinya, apa yang telah kita lihat di sini hari ini adalah bahwa indeks Columnstore secara signifikan dapat mempercepat kueri yang memindai berdasarkan data dalam jumlah besar, dan Toko Kueri akan menangkap eksekusi kueri dan memungkinkan kita memeriksa statistik eksekusi dan kinerja di lain waktu. Pada akhirnya, kami ingin menghasilkan kumpulan hasil yang menunjukkan hal berikut. Perhatikan tiga hal: Kolom dasarnya pivot semua Alasan Kembali yang mungkin, setelah menunjukkan jumlah penjualan Hasil set berisi subtotal oleh tanggal akhir minggu (minggu) di semua klien (di mana Klien adalah NULL) Kumpulan hasil berisi jumlah keseluruhan Baris (dimana Client dan Date keduanya NULL) Pertama, sebelum masuk ke akhir SQL kita bisa menggunakan kemampuan pivotmatrix dinamis di SSRS. Kita hanya perlu menggabungkan dua set hasil dengan satu kolom dan kemudian kita dapat memberi umpan hasilnya pada kontrol matriks SSRS, yang akan menyebarkan alasan pengembalian di sumbu kolom laporan. Namun, tidak semua orang menggunakan SSR (walaupun kebanyakan orang seharusnya). Tapi bahkan saat itu, terkadang pengembang perlu mengonsumsi set hasil dalam sesuatu selain alat pelaporan. Jadi, untuk contoh ini, mari kita asumsikan kami ingin menghasilkan hasil yang ditetapkan untuk halaman grid web dan mungkin pengembang ingin mengeluarkan kuota baris subtotal (di mana saya memiliki nilai ResultSetNum 2 dan 3) dan menempatkannya di kolom ringkasan. Jadi intinya, kita perlu menghasilkan output di atas secara langsung dari prosedur yang tersimpan. Dan sebagai twist tambahan minggu depan mungkin ada Return Reason X dan Y dan Z. Jadi kita tidak tahu berapa banyak alasan pengembalian yang ada. Kami ingin query sederhana untuk berpaling pada kemungkinan nilai yang berbeda untuk Return Reason. Inilah dimana T-SQL PIVOT memiliki batasan yang kita butuhkan untuk memberikan nilai yang mungkin. Karena kita tidak tahu bahwa sampai run-time, kita perlu menghasilkan string query secara dinamis dengan menggunakan pola SQL dinamis. Pola SQL dinamis melibatkan pembuatan sintaks, sepotong demi sepotong, menyimpannya dalam sebuah string, dan kemudian mengeksekusi string di akhir. Dynamic SQL bisa jadi rumit, karena kita harus menanamkan sintaks di dalam sebuah string. Tapi dalam kasus ini, ini satu-satunya pilihan sejati jika kita ingin menangani sejumlah alasan pengembalian. Saya selalu menemukan bahwa cara terbaik untuk menciptakan solusi SQL yang dinamis adalah dengan mencari tahu apa query yang dihasilkan oleh kuotaalquot pada akhirnya (dalam kasus ini, mengingat alasan Kembali yang kita ketahui). Dan kemudian membalik-ulangnya dengan memilah-milahnya Itu bersama satu bagian pada satu waktu. Jadi, inilah SQL yang kita butuhkan jika kita mengetahui Alasan Kembali tersebut (A sampai D) bersifat statis dan tidak akan berubah. Pertanyaannya adalah sebagai berikut: Menggabungkan data dari SalesData dengan data dari ReturnData, di mana kita quothard-wirequot kata Sales sebagai Tipe Aksi membentuk Tabel Penjualan, dan kemudian menggunakan Return Reason dari Return Data ke kolom ActionType yang sama. Itu akan memberi kita kolom ActionType yang bersih untuk diputar. Kami menggabungkan dua pernyataan SELECT ke dalam common table expression (CTE), yang pada dasarnya adalah subquery tabel turunan yang kemudian kami gunakan dalam pernyataan berikutnya (untuk PIVOT) Pernyataan PIVOT melawan CTE, yang menetapkan jumlah dolar untuk Tipe Aksi Berada di salah satu nilai Action Type yang mungkin. Perhatikan bahwa ini bukan hasil akhir. Kami menempatkan ini ke CTE yang berbunyi dari CTE pertama. Alasan untuk ini adalah karena kita ingin melakukan beberapa pengelompokan di akhir. Pernyataan SELECT terakhir, yang terbaca dari PIVOTCTE, dan menggabungkannya dengan query berikutnya melawan PIVOTCTE yang sama, namun di mana kita juga menerapkan dua pengelompokan dalam fitur PENGATURAN SETELAH DI SQL 2008: MENGELOMPOKAN pada Tanggal Akhir Minggu (dbo. WeekEndingDate) PENGELOMPOKAN untuk semua baris () Jadi, jika kita tahu dengan pasti bahwa kita tidak akan pernah memiliki kode alasan pengembalian yang lebih banyak, maka itu akan menjadi solusinya. Namun, kita perlu memperhitungkan kode alasan lainnya. Jadi, kita perlu menghasilkan keseluruhan kueri di atas sebagai satu string besar di mana kita membuat kemungkinan alasan pengembalian sebagai satu daftar dipisahkan koma. Aku akan menunjukkan seluruh kode T-SQL untuk menghasilkan (dan mengeksekusi) kueri yang diinginkan. Dan kemudian aku akan memecahnya menjadi beberapa bagian dan menjelaskan setiap langkahnya. Jadi pertama, inilah keseluruhan kode untuk menghasilkan secara dinamis apa yang telah saya hadapi di atas. Pada dasarnya ada lima langkah yang perlu kita liput. Langkah 1 . Kita tahu bahwa di suatu tempat dalam campuran, kita perlu menghasilkan sebuah string untuk ini dalam query: SalesAmount, Reason A, Reason B, Reason C, Reason D0160016001600160 Apa yang dapat kita lakukan adalah membangun sebuah ekspresi tabel umum sementara yang menggabungkan kutipan kabel keras. Kolom Amountquot dengan daftar kode kemungkinan yang unik. Begitu kita memilikinya di CTE, kita bisa menggunakan sedikit trik bagus untuk XML PATH (3939) untuk menghancurkan baris tersebut menjadi satu string, meletakkan koma di depan setiap baris yang dibaca query, dan kemudian menggunakan STUFF untuk mengganti Contoh koma pertama dengan ruang kosong. Ini adalah trik yang bisa Anda temukan di ratusan blog SQL. Jadi bagian pertama ini membangun sebuah string yang disebut ActionString yang bisa kita gunakan lebih bawah. Langkah 2 . Kami juga tahu bahwa kami ingin SUM kolom alasan dihasilkanproduce, bersama dengan kolom penjualan standar. Jadi kita butuh string terpisah untuk itu, yang akan saya sebut SUMSTRING. Saya hanya akan menggunakan ActionString yang asli, dan kemudian MENGGANTI kurung luar dengan sintaks SUM, ditambah tanda kurung asli. Langkah 3: Sekarang pekerjaan sebenarnya dimulai. Dengan menggunakan kueri asli sebagai model, kami ingin menghasilkan kueri asli (dimulai dengan UNION dari dua tabel), namun mengganti referensi ke kolom berporos dengan string yang kami buat secara dinamis di atas. Selain itu, meski tidak mutlak diperlukan, saya juga menciptakan variabel hanya kombinasi umpan balik jalur kereta yang ingin kami embed ke kueri yang dihasilkan (untuk keterbacaan). Jadi kita akan membangun seluruh query menjadi variabel yang disebut SQLPivotQuery. Langkah 4. Kami terus membangun kueri lagi, menggabungkan sintaks kami dapat kuotot-wirequot dengan ActionSelectString (yang kami buat secara dinamis untuk menyimpan semua nilai alasan pengembalian yang mungkin) Langkah 5. Akhirnya, kami akan menghasilkan bagian terakhir dari Query Pivot, yang terbaca dari persamaan tabel umum 2 (PIVOTCTE, dari model di atas) dan menghasilkan SELECT akhir untuk dibaca dari PIVOTCTE dan menggabungkannya dengan pembacaan 2 terhadap PIVOTCTE ke Menerapkan pengelompokan. Akhirnya, kita bisa quotexecutequot string menggunakan sistem SQL yang tersimpan proc spexecuteSQL Jadi mudah-mudahan Anda dapat melihat bahwa proses untuk mengikuti jenis usaha ini adalah Menentukan apa permintaan akhir, berdasarkan pada kumpulan data dan nilai Anda saat ini (yaitu dibangun Model kueri) Tuliskan kode T-SQL yang diperlukan untuk menghasilkan model kueri tersebut sebagai string. Arguably bagian yang paling penting adalah menentukan seperangkat nilai unik yang menjadi andalan Anda, dan kemudian menghancurkannya menjadi satu string dengan menggunakan fungsi STUFF dan trik FOR XML PATH (3939) Jadi, apa yang ada di pikiran saya hari ini. Setidaknya 13 item Dua Musim panas yang lalu, saya menulis draf BDR yang memusatkan perhatian pada peran pendidikan dan nilai latar belakang seni liberal yang baik tidak hanya untuk industri perangkat lunak tapi juga untuk industri lain. Salah satu tema BDR ini menekankan sudut pandang penting dan tercerahkan dari arsitek perangkat lunak terkenal Allen Holub mengenai seni liberal. Ill (dengan setia) menguraikan pesannya: dia menyoroti kesejajaran antara pemrograman dan mempelajari sejarah, dengan mengingatkan semua orang bahwa sejarah sedang membaca dan menulis (dan Ill menambahkan, mengidentifikasi pola), dan pengembangan perangkat lunak juga membaca dan menulis (dan sekali lagi, mengidentifikasi pola ). Maka saya menulis sebuah opini yang berfokus pada topik ini dan topik terkait lainnya. Tapi sampai hari ini, saya tidak pernah sempat mempublikasikannya. Sering sekali Id memikirkan untuk merevisinya, dan Id bahkan duduk selama beberapa menit dan membuat beberapa penyesuaian untuk itu. Tapi kemudian kehidupan pada umumnya akan menghalangi dan Id tidak pernah menyelesaikannya. Jadi, apa yang berubah Beberapa minggu yang lalu, kolumnis CoDe Magazine dan pemimpin industri Ted Neward menulis sebuah artikel di kolom regulernya, Managed Coder, yang menarik perhatian saya. Judul artikelnya adalah On Liberal Arts. Dan saya sangat menyarankan agar semua orang membacanya. Ted membahas nilai latar belakang seni liberal, dikotomi palsu antara latar belakang seni liberal dan kesuksesan dalam pengembangan perangkat lunak, dan kebutuhan untuk menulis dengan baik. Dia berbicara tentang beberapa pertemuan masa lalunya dengan manajemen personalia HR mengenai latar belakang pendidikannya. Dia juga menekankan perlunya menerima dan menyesuaikan diri dengan perubahan dalam industri kami, sekaligus keunggulan profesional perangkat lunak yang sukses (dapat diandalkan, merencanakan ke depan, dan belajar untuk melewati konflik awal dengan anggota tim lainnya). Jadi bacaannya yang bagus, seperti juga artikel artikel dan blog Tested lainnya. Hal itu juga membuat saya kembali memikirkan pandangan saya tentang topik ini (dan topik lainnya) juga, dan akhirnya memotivasi saya untuk menyelesaikan editorial saya sendiri. Jadi, lebih baik terlambat daripada tidak pernah, inilah Bakers Dozen of Reflections saya saat ini: Saya memiliki pepatah: Air membeku pada suhu 32 derajat. Jika Anda dalam peran pelatihan, Anda mungkin berpikir bahwa Anda melakukan segala sesuatu di dunia untuk membantu seseorang padahal sebenarnya mereka hanya merasakan suhu 34 derajat dan karena itu hal-hal yang menghambat pemadaman untuk mereka. Terkadang dibutuhkan sedikit usaha atau katalis ideacimia lain atau perspektif baru yang berarti bahwa mereka yang memiliki pendidikan sebelumnya dapat memanfaatkan sumber yang berbeda. Air membeku pada suhu 32 derajat. Beberapa orang bisa mempertahankan konsentrasi tinggi meski ruangannya penuh dengan orang yang berisik. Saya tidak salah satu dari mereka kadang-kadang saya memerlukan beberapa privasi untuk memikirkan masalah kritis. Beberapa orang menggambarkan hal ini karena Anda harus belajar untuk menjauh darinya. Dengan kata lain, pencariannya untuk udara yang langka. Seminggu yang lalu aku menghabiskan berjam-jam di ruang sepi dan sepi dengan papan tulis, sampai aku benar-benar mengerti sebuah masalah. Baru pada saat itulah saya bisa berbicara dengan pengembang lain tentang sebuah solusi. Pesan di sini bukan untuk mengkhotbahkan bagaimana Anda harus membicarakan bisnis Anda untuk memecahkan masalah, tetapi bagi setiap orang untuk mengetahui kekuatan dan apa yang berhasil, dan menggunakannya untuk keuntungan Anda sebanyak mungkin. Beberapa ungkapan seperti kuku di papan tulis untukku. Gunakan sebagai momen mengajar adalah satu. (Mengapa seperti kuku di papan tulis Karena jika Anda memiliki peran mentoring, biasanya Anda harus selalu mengikuti mode penglihatan, betapapun halusnya). Heres lain saya cant benar-benar menjelaskannya dengan kata-kata, tapi saya mengerti. Ini mungkin terdengar agak dingin, tapi jika seseorang benar-benar tidak dapat menjelaskan sesuatu dengan kata-kata, mungkin mereka tidak mengerti. Tentu, seseorang dapat memiliki perasaan tidak masuk akal tentang bagaimana sesuatu bekerja. Saya bisa menggertak dengan cara saya menjelaskan bagaimana sebuah karya kamera digital namun kenyataannya saya tidak benar-benar mengerti semuanya dengan baik. Ada bidang studi yang dikenal sebagai epistemologi (studi tentang pengetahuan). Salah satu dasar dasar untuk memahami apakah itu kamera atau pola desain - adalah kemampuan untuk membangun konteks, untuk mengidentifikasi rangkaian kejadian terkait, atribut dari setiap komponen di sepanjang jalan, dll. Ya, pemahaman terkadang sangat kerja keras. , Tapi menyelam ke topik dan memecahnya sepadan dengan usaha. Bahkan mereka yang menjauhkan diri dari sertifikasi akan mengakui bahwa proses belajar untuk tes sertifikasi akan membantu mengisi kesenjangan dalam pengetahuan. Seorang manajer database lebih cenderung mempekerjakan pengembang database yang dapat berbicara secara lantang (dan tanpa susah payah) tentang tingkat isolasi transaksi dan pemicu, berlawanan dengan seseorang yang semacam tahu tentang hal itu namun berjuang untuk mendeskripsikan penggunaannya. Ada konsekuensi lain di sini. Ted Neward merekomendasikan agar pengembang berbicara di depan umum, ngeblog, dan lain-lain. Saya setuju 100. Proses berbicara dan ngomong secara praktis akan memaksa Anda untuk mulai memikirkan topik dan memecah definisi yang mungkin Anda anggap remeh. Beberapa tahun yang lalu saya pikir saya mengerti pernyataan T-SQL MERGE dengan cukup baik. Tapi hanya setelah menulis tentang hal itu, berbicara tentang, mengajukan pertanyaan dari orang lain yang memiliki perspektif yang tidak pernah terpikir oleh saya bahwa tingkat pemahaman saya meningkat secara eksponensial. Saya tahu sebuah cerita tentang seorang manajer perekrutan yang pernah mewawancarai seorang pengembang authord untuk posisi kontrak. Manajer perekrutan itu membenci publikasi secara umum, dan menyalak pada pemohon, Jadi, jika Anda akan bekerja di sini, lebih baik Anda menulis buku atau menulis kode Ya, saya akan memberikan bahwa di industri mana pun akan ada beberapa akademisi murni. Tapi apa yang dilewatkan manajer perekrutan adalah kesempatan untuk memperkuat dan mengasah ketrampilan. Sambil membersihkan kotak buku lama, saya menemukan sebuah harta dari tahun 1980an: Programmer at Work. Yang berisi wawancara dengan Bill Gates yang sangat muda, Ray Ozzie, dan nama-nama terkenal lainnya. Setiap wawancara dan setiap wawasan berharga sesuai dengan harga buku. Menurut saya, wawancara yang paling menarik adalah dengan Butler Lampson. Yang memberikan beberapa saran kuat. Persetan dengan melek komputer. Benar-benar konyol Belajar matematika Belajar berpikir Baca baca. Menulis. Hal-hal ini lebih berharga. Pelajari bagaimana membuktikan teorema: Banyak bukti telah terakumulasi selama berabad-abad yang menunjukkan keterampilan ini dapat dipindahtangankan ke banyak hal lainnya. Butler mengatakan yang sebenarnya. Saya menambahkan pada saat itu bagaimana cara bermain setan menganjurkan diri Anda. Semakin Anda bisa realita-memeriksa proses dan pekerjaan Anda sendiri, semakin baik Anda. Ilmuwan ilmuwan komputer hebat Allen Holub membuat hubungan antara pengembangan perangkat lunak dan seni liberal secara khusus, subjek sejarah. Inilah intinya: apa itu sejarah Membaca dan menulis. Apa itu pengembangan perangkat lunak Antara lain, membaca dan menulis. Dulu saya memberi siswa saya pertanyaan esai T-SQL sebagai tes latihan. Seorang siswa bercanda bahwa saya bertindak lebih seperti profesor hukum. Nah, seperti kata Pelatih Donny Haskins di film Glory Road, jalan saya sulit. Saya sangat percaya pada landasan intelektual yang kuat untuk profesi apapun. Sama seperti aplikasi bisa mendapatkan keuntungan dari kerangka kerja, individu dan proses berpikir mereka bisa mendapatkan keuntungan dari kerangka kerja manusia juga. Itulah dasar dasar beasiswa. Ada sebuah cerita yang kembali di tahun 1970an, IBM memperluas usaha rekrutmen mereka di universitas-universitas besar dengan memusatkan perhatian pada lulusan seni liberal terbaik dan tercerdas. Bahkan kemudian mereka menyadari bahwa pembaca dan penulis terbaik suatu hari nanti bisa menjadi analis programer sistem yang kuat. (Jangan ragu untuk menggunakan cerita itu ke tipe HR mana pun yang menegaskan bahwa seorang kandidat harus memiliki gelar sains komputer) Dan berbicara tentang sejarah: jika tidak ada alasan lain, penting untuk mengingat sejarah peluncuran produk jika saya melakukan pekerjaan di sebuah Situs klien yang masih menggunakan SQL Server 2008 atau bahkan (terkesiap) SQL Server 2005, saya harus mengingat fitur apa yang diimplementasikan dalam versi tersebut dari waktu ke waktu. Pernah memiliki dokter favorit yang Anda sukai karena heshe menjelaskan hal-hal dalam bahasa Inggris, memberi Anda kebenaran langsung, dan mendapatkan kepercayaan Anda untuk beroperasi pada Anda Mereka adalah keterampilan gila. Dan merupakan hasil pengalaman dan KERJA KERAS yang membutuhkan waktu bertahun-tahun dan bahkan berpuluh-puluh tahun untuk berkultivasi. Tidak ada jaminan keberhasilan pekerjaan dalam fokus pada fakta, ambil beberapa risiko yang dihitung saat Anda yakin bisa melihat jalan ke garis finish, biarkan keripik jatuh di mana mereka berada, dan jangan pernah kehilangan pandangan sama seperti dokter yang memperolehnya. Kepercayaan anda Meskipun beberapa hari saya gagal, saya mencoba memperlakukan klien saya dan data mereka sebagai dokter akan merawat pasien. Meskipun seorang dokter menghasilkan lebih banyak uang Ada banyak klise yang saya benci tapi juga yang saya benci: Tidak ada yang namanya pertanyaan buruk. Sebagai mantan instruktur, satu hal yang menarik kemarahan saya adalah mendengar seseorang mengkritik orang lain karena mengajukan pertanyaan yang konyol dan bodoh. Sebuah pertanyaan menunjukkan seseorang mengakui bahwa mereka memiliki beberapa kesenjangan dalam pengetahuan yang ingin mereka isi. Ya, beberapa pertanyaan lebih baik daripada yang lain, dan beberapa pertanyaan memerlukan pembingkaian tambahan sebelum bisa dijawab. Tapi perjalanan dari membentuk sebuah pertanyaan ke sebuah jawaban kemungkinan akan menghasilkan proses mental yang aktif pada orang lain. Ada banyak hal yang baik. Banyak diskusi bagus dan bermanfaat berasal dari pertanyaan bodoh. Saya bekerja di seluruh papan di SSIS, SSAS, SSR, MDX, PPS, SharePoint, Power BI, DAX semua alat di tumpukan Microsoft BI. Saya masih menulis beberapa kode dari waktu ke waktu. Tapi tebak apa yang saya masih menghabiskan begitu banyak waktu untuk menulis kode T-SQL ke data profil sebagai bagian dari proses penemuan. Semua pengembang aplikasi harus memiliki daging T-SQL yang baik. Ted Neward menulis (benar) tentang kebutuhan untuk beradaptasi dengan perubahan teknologi. Saya menambahkan bahwa kebutuhan untuk menyesuaikan diri dengan perubahan pengusaha. Perusahaan mengubah peraturan bisnis. Perusahaan mengakuisisi perusahaan lain (atau menjadi target akuisisi). Perusahaan melakukan kesalahan dalam mengkomunikasikan kebutuhan dan spesifikasi bisnis. Ya, terkadang kita berperan dalam membantu mengelola perubahan tersebut dan terkadang terbang, bukan kaca depan. Ini terkadang menimbulkan rasa sakit yang luar biasa bagi semua orang, terutama I. T. orang-orang. Inilah sebabnya mengapa istilah kehidupan ada kita harus menghadapinya. Sama seperti tidak ada pengembang yang menulis kode bug bebas setiap saat, tidak ada I. T. Orang berurusan dengan baik dengan perubahan setiap saat. Salah satu perjuangan terbesar yang saya miliki dalam 28 tahun saya di industri ini menunjukkan kesabaran dan pengekangan saat perubahan terbang dari berbagai arah. Di sinilah saran saya sebelumnya tentang mencari udara yang bisa diperjelas bisa membantu. Jika Anda dapat mengatur untuk mengasimilasi perubahan ke dalam proses berpikir Anda, dan tanpa merasa terbebani, kemungkinan besar Anda akan menjadi aset yang signifikan. Dalam 15 bulan terakhir saya harus berurusan dengan sejumlah besar perubahan profesional. Sudah sangat sulit, tapi saya telah memutuskan bahwa perubahan itu akan menjadi norma dan saya mencoba meniru kebiasaan saya sebaik mungkin untuk mengatasi perubahan yang sering (dan tidak pasti). Its keras, sangat keras. Tapi seperti yang dikatakan pelatih Jimmy Duggan di film A League of Their Own: Tentu saja susah. Jika tidak sulit, semua orang akan melakukannya. Yang keras, inilah yang membuatnya hebat. Pesan yang kuat Pernah ada pembicaraan di industri ini selama beberapa tahun terakhir tentang perilaku di konferensi profesional (dan berperilaku di industri secara keseluruhan). Banyak penulis yang terhormat telah menulis editorial yang sangat bagus mengenai topik ini. Inilah masukan saya, untuk apa nilainya. Its a message to those individuals who have chosen to behave badly: Dude, it shouldnt be that hard to behave like an adult. A few years ago, CoDe Magazine Chief Editor Rod Paddock made some great points in an editorial about Codes of Conduct at conferences. Its definitely unfortunate to have to remind people of what they should expect out of themselves. But the problems go deeper. A few years ago I sat on a five-person panel (3 women, 2 men) at a community event on Women in Technology. The other male stated that men succeed in this industry because the Y chromosome gives men an advantage in areas of performance. The individual who made these remarks is a highly respected technology expert, and not some bozo making dongle remarks at a conference or sponsoring a programming contest where first prize is a date with a bikini model. Our world is becoming increasingly polarized (just watch the news for five minutes), sadly with emotion often winning over reason. Even in our industry, recently I heard someone in a position of responsibility bash software tool XYZ based on a ridiculous premise and then give false praise to a competing tool. So many opinions, so many arguments, but heres the key: before taking a stand, do your homework and get the facts . Sometimes both sides are partly rightor wrong. Theres only one way to determine: get the facts. As Robert Heinlein wrote, Facts are your single clue get the facts Of course, once you get the facts, the next step is to express them in a meaningful and even compelling way. Theres nothing wrong with using some emotion in an intellectual debate but it IS wrong to replace an intellectual debate with emotion and false agenda. A while back I faced resistance to SQL Server Analysis Services from someone who claimed the tool couldnt do feature XYZ. The specifics of XYZ dont matter here. I spent about two hours that evening working up a demo to cogently demonstrate the original claim was false. In that example, it worked. I cant swear it will always work, but to me thats the only way. Im old enough to remember life at a teen in the 1970s. Back then, when a person lost hisher job, (often) it was because the person just wasnt cutting the mustard. Fast-forward to today: a sad fact of life is that even talented people are now losing their jobs because of the changing economic conditions. Theres never a full-proof method for immunity, but now more than ever its critical to provide a high level of what I call the Three Vs (value, versatility, and velocity) for your employerclients. I might not always like working weekends or very late at night to do the proverbial work of two people but then I remember there are folks out there who would give anything to be working at 1 AM at night to feed their families and pay their bills. Always be yourselfyour BEST self. Some people need inspiration from time to time. Heres mine: the great sports movie, Glory Road. If youve never watched it, and even if youre not a sports fan I can almost guarantee youll be moved like never before. And Ill close with this. If you need some major motivation, Ill refer to a story from 2006. Jason McElwain, a high school student with autism, came off the bench to score twenty points in a high school basketball game in Rochester New York. Heres a great YouTube video. His mother said it all . This is the first moment Jason has ever succeeded and is proud of himself. I look at autism as the Berlin Wall. He cracked it. To anyone who wanted to attend my session at todays SQL Saturday event in DC I apologize that the session had to be cancelled. I hate to make excuses, but a combination of getting back late from Detroit (client trip), a car thats dead (blown head gasket), and some sudden health issues with my wife have made it impossible for me to attend. Back in August, I did the same session (ColumnStore Index) for PASS as a webinar. You can go to this link to access the video (itll be streamed, as all PASS videos are streamed) The link does require that you fill out your name and email address, but thats it. And then you can watch the video. Feel free to contact me if you have questions, at kgoffkevinsgoff November 15, 2013 Getting started with Windows Azure and creating SQL Databases in the cloud can be a bit daunting, especially if youve never tried out any of Microsofts cloud offerings. Fortunately, Ive created a webcast to help people get started. This is an absolute beginners guide to creating SQL Databases under Windows Azure. It assumes zero prior knowledge of Azure. You can go to the BDBI Webcasts of this website and check out my webcast (dated 11102013). Or you can just download the webcast videos right here: here is part 1 and here is part 2. You can also download the slide deck here. November 03, 2013 Topic this week: SQL Server Snapshot Isolation Levels, added in SQL Server 2005. To this day, there are still many SQL developers, many good SQL developers who either arent aware of this feature, or havent had time to look at it. Hopefully this information will help. Companion webcast will be uploaded in the next day look for it in the BDBI Webcasts section of this blog. October 26, 2013 Im going to start a weekly post of T-SQL tips, covering many different versions of SQL Server over the years Heres a challenge many developers face. Ill whittle it down to a very simple example, but one where the pattern applies to many situations. Suppose you have a stored procedure that receives a single vendor ID and updates the freight for all orders with that vendor id. create procedure dbo. UpdateVendorOrders update Purchasing. PurchaseOrderHeader set Freight Freight 1 where VendorID VendorID Now, suppose we need to run this for a set of vendor IDs. Today we might run it for three vendors, tomorrow for five vendors, the next day for 100 vendors. We want to pass in the vendor IDs. If youve worked with SQL Server, you can probably guess where Im going with this. The big question is how do we pass a variable number of Vendor IDs Or, stated more generally, how do we pass an array, or a table of keys, to a procedure Something along the lines of exec dbo. UpdateVendorOrders SomeListOfVendors Over the years, developers have come up with different methods: Going all the way back to SQL Server 2000, developers might create a comma-separated list of vendor keys, and pass the CSV list as a varchar to the procedure. The procedure would shred the CSV varchar variable into a table variable and then join the PurchaseOrderHeader table to that table variable (to update the Freight for just those vendors in the table). I wrote about this in CoDe Magazine back in early 2005 (code-magazinearticleprint. aspxquickid0503071ampprintmodetrue. Tip 3) In SQL Server 2005, you could actually create an XML string of the vendor IDs, pass the XML string to the procedure, and then use XQUERY to shred the XML as a table variable. I also wrote about this in CoDe Magazine back in 2007 (code-magazinearticleprint. aspxquickid0703041ampprintmodetrue. Tip 12)Also, some developers will populate a temp table ahead of time, and then reference the temp table inside the procedure. All of these certainly work, and developers have had to use these techniques before because for years there was NO WAY to directly pass a table to a SQL Server stored procedure. Until SQL Server 2008 when Microsoft implemented the table type. This FINALLY allowed developers to pass an actual table of rows to a stored procedure. Now, it does require a few steps. We cant just pass any old table to a procedure. It has to be a pre-defined type (a template). So lets suppose we always want to pass a set of integer keys to different procedures. One day it might be a list of vendor keys. Next day it might be a list of customer keys. So we can create a generic table type of keys, one that can be instantiated for customer keys, vendor keys, etc. CREATE TYPE IntKeysTT AS TABLE ( IntKey int NOT NULL ) So Ive created a Table Typecalled IntKeysTT . Its defined to have one column an IntKey. Nowsuppose I want to load it with Vendors who have a Credit Rating of 1..and then take that list of Vendor keys and pass it to a procedure: DECLARE VendorList IntKeysTT INSERT INTO VendorList SELECT BusinessEntityID from Purchasing. Vendor WHERE CreditRating 1 So, I now have a table type variable not just any table variable, but a table type variable (that I populated the same way I would populate a normal table variable). Its in server memory (unless it needs to spill to tempDB) and is therefore private to the connectionprocess. OK, can I pass it to the stored procedure now Well, not yet we need to modify the procedure to receive a table type. Heres the code: create procedure dbo. UpdateVendorOrdersFromTT IntKeysTT IntKeysTT READONLY update Purchasing. PurchaseOrderHeader set Freight Freight 1 FROM Purchasing. PurchaseOrderHeader JOIN IntKeysTT TempVendorList ON PurchaseOrderHeader. VendorID Te mpVendorList. IntKey Notice how the procedure receives the IntKeysTT table type as a Table Type (again, not just a regular table, but a table type). It also receives it as a READONLY parameter. You CANNOT modify the contents of this table type inside the procedure. Usually you wont want to you simply want to read from it. Well, now you can reference the table type as a parameter and then utilize it in the JOIN statement, as you would any other table variable. Jadi begitulah. A bit of work to set up the table type, but in my view, definitely worth it. Additionally, if you pass values from , youre in luck. You can pass an ADO data table (with the same tablename property as the name of the Table Type) to the procedure. For developers who have had to pass CSV lists, XML strings, etc. to a procedure in the past, this is a huge benefit. Finally I want to talk about another approach people have used over the years. SQL Server Cursors. At the risk of sounding dogmatic, I strongly advise against Cursors, unless there is just no other way. Cursors are expensive operations in the server, For instance, someone might use a cursor approach and implement the solution this way: DECLARE VendorID int DECLARE dbcursor CURSOR FASTFORWARD FOR SELECT BusinessEntityID from Purchasing. Vendor where CreditRating 1 FETCH NEXT FROM dbcursor INTO VendorID WHILE FETCHSTATUS 0 EXEC dbo. UpdateVendorOrders VendorID FETCH NEXT FROM dbcursor INTO VendorID The best thing Ill say about this is that it works. And yes, getting something to work is a milestone. But getting something to work and getting something to work acceptably are two different things. Even if this process only takes 5-10 seconds to run, in those 5-10 seconds the cursor utilizes SQL Server resources quite heavily. Thats not a good idea in a large production environment. Additionally, the more the of rows in the cursor to fetch and the more the number of executions of the procedure, the slower it will be. When I ran both processes (the cursor approach and then the table type approach) against a small sampling of vendors (5 vendors), the processing times where 260 ms and 60 ms, respectively. So the table type approach was roughly 4 times faster. But then when I ran the 2 scenarios against a much larger of vendors (84 vendors), the different was staggering 6701 ms versus 207 ms, respectively. So the table type approach was roughly 32 times faster. Again, the CURSOR approach is definitely the least attractive approach. Even in SQL Server 2005, it would have been better to create a CSV list or an XML string (providing the number of keys could be stored in a scalar variable). But now that there is a Table Type feature in SQL Server 2008, you can achieve the objective with a feature thats more closely modeled to the way developers are thinking specifically, how do we pass a table to a procedure Now we have an answer Hope you find this feature help. Feel free to post a comment. SQL Server 2012 Analysis Services (SSAS) DMVs By: Scott Murray Read Comments (6) Related Tips: Analysis Services Administration What are the SQL Server Analysis Services (SSAS) 2012 DMVs and how can they be used In my previous tip on XMLA both the Execute and Discover methods were discussed in context of running XMLA queries. The discover method exposes metadata about a SSAS database however the data is returned in XML form. As an alternative to the discover method, SSAS provides a group of dynamic management views (DMVs for short) which can be queried to return the same data as the discover method. However, by using these DMVs, the data is returned in a tabular format which is generally easier to read and use as a basis for reports. The queries are DMX, but they have the look and feel of SQL with some caveats. The DMVs can be broken up into two main categories: the DBSCHEMAMDSCHEMA DMVs which retrieve metadata about the SSAS database, such as cube structure and dimension structure and the Discover DMVs which retrieve monitoring data such a current connections and locks. SSAS MDSCHEMA and DBSCHEMA DMVs The SSAS DMVs act in many ways like regular SQL DMVs and return data in a table format, at least in most cases. The information that can be queried covers everything from the connections that are currently active to the amount of memory being used to what dimensions are part of the cube. Furthermore, you can even query a dimension to get its members. Even though the queries are SQL-like, you can not use the following: Last, and probably equally important, in order to run queries against the SSAS database, system administrator permissions are required. The best way to show what the views can do is to review several number of examples which will in turn convey the limitations that come into play with several of the DMVs. Probably the best place to start is with a query to get a list of the DMVs available to query. The below MDX queries will display the list of views which can be queried. Note that the word views is used very loosely as these DMVs are SQL-like but not pure SQL. In order to run these queries, open SSMS and connect to your SSAS database as displayed below. For our examples we will be using the AdventureWorks 2012 DataWarehouse sample database available on CodePlex, msftdbprodsamples. codeplexreleasesview55330. Be sure to select the AdventureWorksDW2012 database and verify the query type is set to MDX. If MDX is not selected, you can set the query type by clicking on the MDX button in the tool bar. The query results are partially displayed in the below screen print. This table list is roughly equivalent to the DMVs that are available to query against the SSAS database. For details on each of these row sets, MSDN has a DMV reference sheet available at: msdn. microsoften-uslibraryhh230820.aspxbkmkref. Next, we can run the following query to get a list of cubes in a particular database. Of course there are a few caveats with the query results shown below. First you will notice that only two cubes are displayed in the objective explorer (left side of above screen print), while the query results show seven rows. The reason for this discrepancy is that the results include Perspectives in addition to the regular cubes. Thus, a simple way to return just the cubes and not the perspectives is to adjust our query as shown in the next illustration. In this case, the criteria in the where clause is a bit of cheat in that it looks for a blank value for the BaseCubeName by using the less than operator. Next we can get a list of dimensions using the MDSCHEMADIMENSIONS DMV. Of course a few caveats exists with the query results shown below. The dimensions are listed multiple times for instance, the Account dimension is listed seven times. One dimension exists for each cube measure group additionally, one dimension, the one whose cube name begins with the is the cube level dimension. Furthermore, the dimension caption displays the name that the end users see. Drilling into the dimension, we can next use the MDSCHEMAMEASUREGROUPDIMENSIONS DMV, as displayed below. This DMV breaks out the dimensions at the measure group granularity level. Notice that I have included two items in the Order By clause. Unfortunately, including more than one item in the order clause is not supported and produces the following error. Using just one order by field and adding the cube name to the where clause produces better results which are illustrated below. Again, notice we have duplicates as we did before with the MDSCHEMADIMENSIONS DMV. Before moving on to some of the monitoring DMVs, lets review the measure MDSCHEMAMEASURES DMV. As illustrated below, in addition to the normal name and visibility information available from the dimension DMVs, the MDSCHEMAMEASURES DMV conveys the format used for the measure and the aggregation method, which tells how to aggregate the measure such as Sum, Average, or Custom (see msdn. microsoften-uslibraryms126250.aspx ). The DMV also displays the formula used in a calculated measure in the Expression field which is helpful when checking multiple calculated values at one time non calculated measure have no data in the expression field. SSAS Discover DMVs The SSAS Discover DMVs retrieve data used to monitor a SSAS database. Some data points that can be retrieved include the query execution times, current locks, CPU and memory usage, and current connections. We will start with the DISCOVERCONNECTIONS DMV. This DMV provides us with a wealth of details about the current sessions including the Last Command to be run, how long the command took to run, how much memory the session used, and how many reads and writes were used. This DISCOVERCOMMANDS DMV provides us with similar information at the command level. You will also notice that you can do a Select to retrieve all columns from the DMV however, just as with other select statements, I would recommend only retrieving the columns needed. Some of the Discover DMVs require the use of SYSTEMRESTRICTSCHEMA and also require passing in additional parameters. In essence, this means that instead of writing a select directly against the DMV, we query the SYSTEMRESTRICTSCHEMA and then specify the DMV and any other parameters required when writing the query. For example, the below query integrates the DISCOVERINSTANCES DMV. In this case, only one parameter is required, INSTANCENAME. Notice how the from uses the SYSTEMRESTRICTSCHMEA. The DISCOVERINSTANCES DMV returns the following data about the instance. Using the SYSTEM. DBSCHEMATABLES DMV, you can explore many of the other Discover SSAS DMVs. Conclusion Using the SSAS DMVs can return a plethora of information about a SSAS cubes metadata and a cubes current state, from a monitoring standpoint. These DMVs are easier to use than XMLA related queries as the data is returned in tabular format and the queries are written, in most cases, in a SQL-like manner. The results, depending on the DMV, can provide much of the information needed for a SSAS administrator to profile and monitor the SSAS cubes. Next Steps Last Update: 7262013Using DAX to retrieve tabular data Robert Sheldon In my last article, 8220Getting Started with the SSAS Tabular Model ,8221 I introduced you to the SQL Server Analysis Services (SSAS) tabular database and how to access its components in SQL Server Management Studio (SSMS). This article continues that discussion by demonstrating how to use the Data Analysis Expressions (DAX) language to retrieve data from your tabular database. DAX has a rather unique history in that it8217s a formula language with its roots in PowerPivot, an in-memory data exploration tool that brought the tabular model to Excel. In fact, DAX is often considered an extension to the formula language used in Excel. When Microsoft added support for the tabular model in SSAS 2012, they included support for both DAX and Multidimensional Expressions (MDX), the language traditionally used to access SSAS multidimensional data. You can use either DAX or MDX to query data in an SSAS tabular database. However, you cannot use MDX if the database is configured to run in DirectQuery mode. In addition, some client applications, such as Power View, can issue DAX queries only. As a result, if you plan to support tabular databases, you should have at least a basic understanding of how to use DAX to access data in those databases. Because DAX has its roots in PowerPivot, much of what has been written about the language has focused on how to create expressions that define measures and calculated columns. But there might be times when you want to use DAX to access data directly from a tabular database, either by issuing queries in SSMS or by creating them in other client applications. This article explains how to get started writing DAX queries within SSMS and provides numerous examples that demonstrate each concept. For these examples, we use the AdventureWorks Tabular Model SQL 2012 database, available as a SQL Server Data Tools tabular project from the AdventureWorks CodePlex site. Retrieving Table Data To query data in an SSAS tabular database from within SSMS, you must first connect to the SSAS instance that contains the database and then open an MDX query window. You have to use an MDX query window because SSMS currently does not support a DAX-specific query window. However, you can write DAX queries directly in the MDX window without taking any other steps. When using DAX to retrieve tabular data, your entire statement is founded on the evaluate clause. The clause begins with the evaluate keyword, followed by a table expression, enclosed in parenthesis. The table expression defines the results of your query. The simplest table expression is one that specifies the name of the table, enclosed in single quotes. When you specify only the table name, all rows and columns are returned. For example, the following evaluate clause retrieves all data from the InternetSales table: Notice that you first specify the order by keywords, followed by the column name on which you want to order the data. If can include more than one column, but you must separate them with a comma. When specifying the column name, you must precede it with the table name, enclosed in single quotes, and then the column name, enclosed in brackets. This method of referencing a column is typical of the approach you generally use when referencing columns in your DAX statements. With the addition of the order by clause, the results are now sorted by the ProductKey column, as shown in Figure 2. Figure 2: Ordering a result set based on the ProductKey values As handy as it is to be able to pull all the data from a table, more often than not you won8217t want to. For instance, at times you8217ll likely want to retrieve only specific columns. Unfortunately, DAX makes retrieving only some table columns a less than straightforward process, so you must use a workaround to get the information you need. One of the easiest solutions is to use the summarize function. This function groups data based on specified columns in order to aggregate data in other columns, similar to how a GROUP BY clause works in a T-SQL SELECT statement. However, you can also use the summarize function to return all rows in a table without grouping any of the data. To do so, you must first include a column or columns that uniquely identify each row in the table. For example, the following evaluate clause uses the summarize function to retrieve the Sales Order Number and Sales Order Line Number columns: When you use the summarize function, you specify the function name and then the arguments passed into the function. The first argument is your base table. All subsequent arguments are the columns you want to include in the result set. As you can see in the above example, the arguments are enclosed in parentheses and separated with commas. The summarize function groups the data by the values in the specified columns. However, together the Sales Order Number and Sales Order Line Number columns uniquely identify each row in the table, so all rows are returned and no values are grouped or summarized. Notice, too, that the order by clause now includes the two columns specified in the summarize function, separated by a comma. Figure 3 shows some of the rows returned by the DAX statement: Figure 3: Retrieving distinct values from a table If you were to scroll down these results, you would find a number of repeating Sales Order Number values, but each set of the repeated values would include unique Sales Order Line Number values, which is what makes each row unique. In other words, no two rows would share the same Sales Order Number value and the same Sales Order Line Number value. Of course, you8217re likely to want to include additional columns as well, once you8217ve identified the columns that uniquely identify each row, in which case, you need only add those columns to the mix. In the following example, the ProductKey and OrderDate columns have been added to the summarize function: As you can see in Figure 4, the results now include the additional columns, sorted by the Sales Order Number and Sales Order Line Number columns. Figure 4: Retrieving specific columns from a table The examples so far have demonstrated how to return all rows in a table. However, the nature of SSAS and the tabular model suggest that, in many cases, you8217ll want to work with summarized data. After all, conducting meaningful analysis often depends on the ability to aggregate large datasets. And the summarize function can help perform much of that aggregation. So let8217s take a closer look at that function. Summarizing Data As mentioned earlier, the columns you specify in the summarize function form the basis of how the data is grouped. In the previous two examples, we chose columns that uniquely identified each row, so no real grouping was performed, at least not in the sense that one would expect from a function used to group and summarize data. However, suppose we were to now remove the Sales Order Number and Sales Order Line Number columns, as shown in the following example: As you can see, this time round we8217re grouping our data on the ProductKey and Order Date columns only, and we8217re also doing something else, adding a third column that aggregates the data. The new column is considered a calculated column (or extension column). When adding a calculated column in this way, we include two parts. The first is the name of the new column ( Total Sales Amount ), enclosed in double quotes. The second part is an expression that defines the column8217s values. In this case, we8217re using the sum aggregate function to add together the Sales Amount values. To do so, we need only specify the function name, followed by the column, enclosed in parentheses. Now our results include three columns, with the values grouped together by the ProductKey and Order Date columns and the amount of sales for each grouping added to the Total Sales Amount column, as shown in Figure 5. Figure 5: Summarizing data in a table As you can see, DAX lets us easily get the data we need from our table. However, you might find that you want to include columns from other tables in your result set, as you would when joining tables in a T-SQL SELECT statement. Fortunately, DAX and the tabular model makes it simple to retrieve these columns. For example, suppose we want to retrieve the product names instead of the product numbers and the order year instead of a specific date and time. We can easily achieve this by modifying our summarize function as follows: As you can see, in place of the ProductKey column, we now have the Product Name column from the Product table, and instead of the Order Date column we have the Calendar Year column from the Date table. NOTE: Pulling data from the Calendar Year column in this way masks the fact that multiple relationships exist between the Internet Sales table and the Date table. The first of these relationships is defined on the OrderDateKey column in the Internet Sales table. As a result, the Calendar Year value returned by our statement is based on the date represented by that key. An explanation of the logic behind all this is beyond the scope of this article, but know that what we8217ve done in our example serves its main purpose: to demonstrate how easily we can retrieve data from other tables. In addition to switching out columns, we8217ve also updated our order by clause to reflect the new columns. Now are results our substantially different, as shown in Figure 6. Figure 6: Retrieving data from other tables As you can see, we8217ve grouped our data first by product name and then by the calendar year, with sales totals provided for each group. If you were to scroll down the list, you would find that our results include other years as well. Not surprisingly, these results are much quicker to comprehend because they include easily identifiable information: the product names and sales years. In addition, we can easily add more columns. The following example is similar to the last but now includes the Product Subcategory Name column from the Product Subcategory table and the Product Category Name column from the Product Category table: To use the ROLLUP function, you need only to precede the column name with the function name and enclose the column name in parentheses. As you can see in Figure 8, our results now include an additional row for each product. The new row provides totals for that product for all years. Figure 8: Using the ROLLUP operator to summarize data Not surprisingly, there8217s far more you can do when using DAX to summarize data, but what we8217ve covered here should help you get started. And you8217ve seen how specific we can be in terms of which columns we return. So now let8217s look at how we can filter data even further. Filtering Data One of the easiest ways to filter data in a DAX statement is to use the filter function. The function takes two arguments: a table expression and a filter. The table expression can be the name of a table or an expression that returns a table. The filter is a Boolean expression that is evaluated for each row returned by the table expression. Any row for which the expression evaluates to true is included in the result set. Let8217s look at an example to better understand how the filter function works. In the following evaluate clause, the filter function filters data in the Internet Sales table: In our example, we once again we start with a filter function, but this time, as our first argument, we use the addcolumns function to return a table. The addcolumns function takes as its first argument a table or table expression. In this case, we8217re using the Product table. After we specify our table, we add a definition for a calculated column, just like we did with the summarize function. In this case, however, the column is named Net Profit . and the column8217s values are based on an expression that subtracts the Standard Cost value from the List Price column. We then filter our results so that only rows with a List Price value greater than 0 are included in the result set. Figure 9 shows part of the results returned by the DAX statement. Notice the Net Profit column added after all the table8217s other columns. Figure 9: Adding columns to a table Of course, you8217ll often want to be more specific with your table expression, rather than simply returning the entire table. For example, you can use the summarize function as your table expression. In fact, the addcolumns function can be particularly helpful when used in conjunction with the summarize function. Let8217s take a step back. As you8217ll recall from earlier examples, we used the summarize function to add the Total Sales Amount and Total Cost computed columns to our result set. However, in some cases, you8217ll see better performance if you use the addcolumns function to create those columns, rather than creating the computed columns within the summarize function, as shown in the following example: In this case, the summarize function specifies only the columns on which to group the data. The function returns a table as the first argument to the addcolumns function. We can then add our computed columns as arguments to the addcolumns function. The only thing to remember, however, if we add columns in this way and those columns aggregate data, we must also use the calculate function to call our aggregated column. (This has to do with the context in which DAX evaluates data.) Figure 10 shows part of the results returned by the DAX statement. Figure 10: Adding columns when summarizing data Using the addcolumns function to add computed columns works in most, but not all, situations. For example, you cannot use this approach when you want to use the ROLLUP function. (Be sure to check the DAX documentation for specifics on when to use addcolumns .) However, when you can use the addcolumns function in conjunction with the summarize function, you should see better performance. Moving Ahead with DAX Now that you8217ve gotten a taste of how to use DAX to retrieve tabular data, you should be ready to start putting DAX to work. Keep in mind, however, that what we8217ve covered here only scratches the surface of what you can do with DAX. It is a surprisingly rich language that includes a number of methods for retrieving and summarizing data. In future articles in this series, we8217ll look at how to access a tabular data from other client applications, often using DAX in the process. What you8217ve learned in this article should provide you with the foundation you need to facilitate that data access. Keep in mind, however, that the better you understand DAX, the better you8217ll be able to make use of your tabular data. Subscribe for more articles Fortnightly newsletters help sharpen your skills and keep you ahead, with articles, ebooks and opinion to keep you informed. Want more Subscribe to our fortnightly newsletter Related articles Also in Database With the rise of NoSQL databases that are exploiting aspects of SQL for querying, and are embracing full transactionality, is there a danger of the data-document models hierarchical nature causing a fundamental conflict with relational theory We asked our relational expert, Hugh Bin-Haad to expound a difficult area for database theorists. hellip Read more Also in DAX Following on from his first four articles on using Data Analysis Expressions (DAX) with tabular databases, Robert Sheldon dives into some of the DAX statistical functions available, demonstrating which are the most useful and examples of how they work. hellip Read more Also in PowerPivot Although it is well-known how to create a tabular database in PowerPivot, it is less obvious that there are several useful options for retrieving SSAS tabular data into Excel. This provides an easy way of manipulating, visualizing and analyzing the data without needing to know the details of SSAS and the tabular model. hellip Read more Also in Reporting Services The Power Query Formula Language (PQFL) is a functional language that drives the Power BI transformations, and allows you to create mashup queries from scratch. Rob demonstrates how to use it in Power BI Desktop to extract data from its source, filter rows, specify the columns, clean the data, and create visualisations. hellip Read more copy 2005 - 2017 Red Gate Software Ltd What do you think of the new Simple Talk Give us your feedback

No comments:

Post a Comment