Jump to content

antonch

Administrators
  • Posts

    1030
  • Joined

  • Last visited

  • Days Won

    7

Blog Entries posted by antonch

  1. antonch
    Το παρακάτω query είναι πάρα πολύ καλό!!!.
    Το ξαναβρήκα τυχαία μπροστά μου καθώς σκάλιζα τα διάφορα scripts που έχω στην βιβλιοθήκη μου. Αν θυμάμαι καλά, γιατί έχει περάσει καιρός, το έχει φτιάξει ένα παλικάρι από την μαμά εταιρία, νομίζω ότι είναι ο Swapnil Bajaj.
    Κάνει φοβερή εκμετάλευση των dymamic views (DMV)
    sys.dm_db_missing_index_group_stats, sys.dm_db_missing_index_groups, sys.dm_db_missing_index_details. Θα σας συνιστούσα να διαβάσετε το documentation στα BOL του SQL Server γιατί έχουν κάποιες "ιδιοτροπίες" οι συγκεκριμένες DMV.
    Επίσης παράγει και το script για την δημιουργία του index .
    Enjoy it.
     


    Code Snippet


    SELECT   sys.objects.name, (avg_total_user_cost * avg_user_impact) * (user_seeks + user_scans) as Impact,   cast('CREATE NONCLUSTERED INDEX ~NewNameHere~ ON ' + sys.objects.name + ' ( ' + mid.equality_columns + CASE WHEN mid.inequality_columns IS NULL THEN '' ELSE CASE WHEN mid.equality_columns IS NULL THEN '' ELSE ',' END +     mid.inequality_columns END + ' ) ' + CASE WHEN mid.included_columns IS NULL THEN '' ELSE 'INCLUDE (' + mid.included_columns + ')' END + ';' as xml) AS CreateIndexStatement, mid.equality_columns, mid.inequality_columns, mid.included_columns FROM sys.dm_db_missing_index_group_stats AS migs     INNER JOIN sys.dm_db_missing_index_groups AS mig ON migs.group_handle = mig.index_group_handle     INNER JOIN sys.dm_db_missing_index_details AS mid ON mig.index_handle = mid.index_handle     INNER JOIN sys.objects WITH (nolock) ON mid.object_id = sys.objects.object_id WHERE (migs.group_handle IN(SELECT TOP (500) group_handle                             FROM sys.dm_db_missing_index_group_stats WITH (nolock)                             ORDER BY (avg_total_user_cost * avg_user_impact) * (user_seeks + user_scans) DESC)) ORDER BY 2 DESC



  2. antonch
    Καλησπέρα σας. Τι έγινε κουνηθήκαμε λιγάκι σήμερα ε;
    Λοιπόν αυτό ήταν καλό γιατί μου ήρθε η ιδέα για το post αυτό.
    Επειδή είναι αδύνατο, τουλάχιστον για μένα, να τα θυμάμαι όλα απ’ έξω, σας δίνω μερικά links στα οποία θα βρείτε cheat sheets για την T-SQL.
    TSQL Cheatsheet SQL Server TSQL Cheatsheet Dave Pinal or SQL Authority's Cheatsheet Φιλικά
    Αντώνης
  3. antonch
    Καλημέρα και καλό μήνα σε όλους.

    Σήμερα έπεσα πάνω σε ένα μήνυμα λάθους το οποίο με προβλημάτισε αρκετά. Μέσα από ένα CLR Trigger έπαιρνα το παρακάτω μήνυμα λάθους


    A .NET Framework error occurred during execution of user-defined routine or aggregate "…":

    System.InvalidOperationException: Data access is not allowed in this context. Either the context is a function or method not marked with DataAccessKind.Read or SystemDataAccessKind.Read, is a callback to obtain data from FillRow method of a Table Valued Function, or is a UDT validation method.


    Έπειτα από την σχετική έρευνα βρήκα το παρακάτω link το οποίο δίνει λύση στο προβλημα You may not be able to make a remote connection to SQL Server from a CLR trigger
  4. antonch
    Πρόσφατα αντιμετώπισα ένα πρόβλημα στα SQL Server 2005 Reporting Services.
    Ενώ όλα ήταν μια χαρά και όλοι μέσα στην εταιρεία δούλευαν μια χάρα, ένα πρωί όπως συμβάνει πάντα σε αυτές τις περιπτώσεις είχαν σπάσει τα τηλέφωνα, είχα 40 mail, και 20 msn χρήστες να θέλουν να μιλήσουν μαζί μου.
    Τι έγινε ρε παιδιά...
    1. πήραμε φωτία;
    2. δεν θα βγει ο Ομπάμα;
    3. θα μας πέσει ο ουρανός στο κεφάλι;
    Τιποτα από όλα αυτά, απλά, όταν πήγαιναν να τυπώσουν είχαν ένα ώραίο μύνημα που τους έλεγε "Unable to load client print control".
    Μετά από ψάξιμο βρήκα ότι η αιτία είναι ότι ένα security patch μπλοκάρει τη εκτέλεση του συγκεκριμένου dll και η λύση είναι
    1. Κατεβάσουμε το Microsoft Report Viewer Redistributable 2005 Service Pack 1
    2. Πάμε και κάνουμε unistall τα security patches KB956803 & KB956391 και από τον server αλλα και από τους clients
    3. Στήνουμε το Microsoft Report Viewer Redistributable 2005 Service Pack 1
    4. Κάνουμε restart τον server
  5. antonch
    Επειδή αρκετές φορές με ρωτούν αν ο SQL Server έχει κάποια όρια σας παραθέτω τα όρια του
    Database Engine Object
    x32 x64 Batch size1
    65,536 * Network Packet Size
    65,536 * Network Packet Size
    Bytes per short string column
    8,000
    8,000
    Bytes per GROUP BY, ORDER BY
    8,060
    8,060
    Bytes per index key2
    900
    900
    Bytes per foreign key
    900
    900
    Bytes per primary key
    900
    900
    Bytes per row8
    8,060
    8,060
    Bytes in source text of a stored procedure
    Lesser of batch size or 250 MB
    Lesser of batch size or 250 MB
    Bytes per varchar(max), varbinary(max), xml, text, or image column
    2^31-1
    2^31-1
    Characters per ntext or nvarchar(max) column
    2^30-1
    2^30-1
    Clustered indexes per table
    1
    1
    Columns in GROUP BY, ORDER BY
    Limited only by number of bytes
    Limited only by number of bytes
    Columns or expressions in a GROUP BY WITH CUBE or WITH ROLLUP statement
    10
    10
    Columns per index key7
    16
    16
    Columns per foreign key
    16
    16
    Columns per primary key
    16
    16
    Columns per base table
    1,024
    1,024
    Columns per SELECT statement
    4,096
    4,096
    Columns per INSERT statement
    1,024
    1,024
    Connections per client
    Maximum value of configured connections
    Maximum value of configured connections
    Database size
    1,048,516 terabytes
    1,048,516 terabytes
    Databases per instance of SQL Server
    32,767
    32,767
    Filegroups per database
    32,767
    32,767
    Files per database
    32,767
    32,767
    File size (data)
    16 terabytes
    16 terabytes
    File size (log)
    2 terabytes
    2 terabytes
    Foreign key table references per table4
    253
    253
    Identifier length (in characters)
    128
    128
    Instances per computer
    16
    16
    Length of a string containing SQL statements (batch size)1
    65,536 * Network packet size
    65,536 * Network packet size
    Locks per connection
    Maximum locks per server
    Maximum locks per server
    Locks per instance of SQL Server5
    Up to 2,147,483,647
    Limited only by memory
    Nested stored procedure levels6
    32
    32
    Nested subqueries
    32
    32
    Nested trigger levels
    32
    32
    Nonclustered indexes per table
    249
    249
    Parameters per stored procedure
    2,100
    2,100
    Parameters per user-defined function
    2,100
    2,100
    REFERENCES per table
    253
    253
    Rows per table
    Limited by available storage
    Limited by available storage
    Tables per database3
    Limited by number of objects in a database
    Limited by number of objects in a database
    Partitions per partitioned table or index
    1,000
    1,000
    Statistics on non-indexed columns
    2,000
    2,000
    Tables per SELECT statement
    256
    256
    Triggers per table3
    Limited by number of objects in a database
    Limited by number of objects in a database
    UNIQUE indexes or constraints per table
    249 nonclustered and 1 clustered
    249 nonclustered and 1 clustered
    User connections
    32,767
    32,767
    XML indexes
    249
    249

    1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. The default packet size is 4 kilobytes (KB), and is controlled by the network packet size configuration option.
    2 The maximum number of bytes in any index key cannot exceed 900 in SQL Server 2005. You can define a key using variable-length columns whose maximum sizes add up to more than 900, provided no row is ever inserted with more than 900 bytes of data in those columns. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the maximum index key size of 900 bytes. For more information, see Index with Included Columns.
    3 Database objects include objects such as tables, views, stored procedures, user-defined functions, triggers, rules, defaults, and constraints. The sum of the number of all objects in a database cannot exceed 2,147,483,647.
    4 Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query optimizer to process.
    5 This value is for static lock allocation. Dynamic locks are limited only by memory.
    6 If a stored procedure accesses more than 8 databases, or more than 2 databases in interleaving, you will receive an error.
    7 If the table contains one or more XML indexes, the clustering key of the user table is limited to 15 columns because the XML column is added to the clustering key of the primary XML index. In SQL Server 2005, you can include nonkey columns in a nonclustered index to avoid the limitation of a maximum of 16 key columns. For more information, see Index with Included Columns.
    8 SQL Server 2005 supports row-overflow storage which enables variable length columns to be pushed off-row. Only a 24-byte root is stored in the main record for variable length columns pushed out of row; because of this, the effective row limit is higher than in previous releases of SQL Server. For more information, see the "Row-Overflow Data Exceeding 8 KB" topic in SQL Server 2005 Books Online.
  6. antonch
    O SQL Server έχει αρκετά εργαλεία για να κάνεις export & import data. Από τα απλά T-SQL BULK INSET ή το κλασσικό BCP μέχρι τα DTS (Data Transformation Services)  και σήμερα τα SSIS ( SQL Server Integration Services).

    Όμως υπάρχουν αρκετές περιπτώσεις που δεν θα ήθελες να εμπλακείς με αυτά.

    Ένα σενάριο το οποίο κάποια στιγμή σε ένα project μου έτυχε ήταν η απαίτηση να πατάει ο χρήστης ένα κουμπί και να γίνονται τα δεδομένα export σε Excel αρχείο.

    Για να δούμε λοιπόν την υλοποίηση του χωρίς να χρησιμοποιήσω κάτι από τα παραπάνω αλλά κάνοντας χρήση αγνού T-SQL και της δυνατότητας που έχει ο SQL Server με τους Linked Servers.

    Βασική προϋπόθεση για να μπορέσει η λύση να δουλέψει είναι να δημιουργήσεις ένα άδειο αρχείο excel στο server με συγκεκριμένο όνομα και σε συγκεκριμένο directory. Ας το πούμε empty.xls και ας το βάλουμε στο c:\temp. Αυτό θα λειτουργεί σαν template για τα αρχεία που δα δημιουργήσουμε παρακάτω.

    Όμως δεν φτάνει μόνο αυτό.

    Θα πρέπει να ανοίξω το excel αρχείο και να δώσω ένα όνομα στο φύλλο (πχ MyData).

    Ακόμα θα πρέπει να γνωρίζω πόσα πεδία θα βάλω στο excel φύλλο πχ αν ξέρω ότι θα βάλω 2 πεδία θα πρέπει στα πρώτα 2 κελιά της πρώτης γραμμής να δώσω κάποιο όνομα πχ A,B.

    Φτιάχνω την stored procedure που θα κάνει όλη την δουλειά


    create proc usp_write2Excel (@fileName varchar(100),@NumOfColumns tinyint,@query varchar(200))

    as

    begin

    declare @dosStmt varchar(200)

    declare @tsqlStmt varchar(500)

    declare @colList varchar(200)

    declare @charInd tinyint

    set nocount on

    --
    -- COLUMNS LIST CREATION

    --
    set @charInd=0

    set @colList = 'A'

    while @charInd
    begin

    set @charInd = @charInd + 1

    set @colList = @colList + ',' + char(65+ @charInd)

    end

    -- CREATE MY EXCEL FILE BY COPING EXCEL TEMPLATE

    set @dosStmt = ' copy c:\temp\empty.xls ' + @fileName

    exec master..xp_cmdshell @dosStmt

    -- Create a "temporary" linked server to that file in order to "Export" Data

    EXEC sp_addlinkedserver 'ExcelSource','Jet 4.0','Microsoft.Jet.OLEDB.4.0',@fileName,NULL,'Excel 5.0'

    -- construct a T-SQL statement that will actually export the query results-- to the Table in the target linked server

    set @tsqlStmt = 'Insert ExcelSource...[MyData$] ' + ' ( ' + @colList + ' ) '+ @query

    -- execute dynamically the TSQL statement

    exec (@tsqlStmt)

    -- drop the linked server

    EXEC sp_dropserver 'ExcelSource'

    set nocount off

    end

    GO

    Execute sp

    exec usp_write2Excel 'c:\temp\Customers.xls',2,'select customerid,companyname from northwind.dbo.customers'




    Αυτό ήταν έχεις τα δεδομένα σου σε Excel!!!  
  7. antonch
    Επειδή είμαι μεγάλος τεμπέλης αλλά και επειδή θέλω να τελειώνω γρήγορα με τις τυχόν αλλαγές που θα προκείψουν πάντα έφτιαχνα stored procedures με "δυναμικές" παραμέτρους
    Τώρα με το SQL Server 2005 τα πράγματα είναι αρκετά καλύτερα εξαιτίας 2 χαρακτηριστικών
    1. το νέο xml data type
    2. τον "integrated" XML Parser
    Ψάχνοντας από εδώ και από εκεί βρήκα αυτό, το οποίο είναι αρκετά ενδιαφέρον για να το δείτε και πιστεύω ότι αξίζει τον κόπo (PDF)
  8. antonch
    Όπως όλοι γνωρίζουμε μια από τις system databases του SQL Server είναι η tempdb. Λίγοι είναι όμως γνωρίζουν το ρόλο αλλά και την σημασία της database αυτής.
    Και για να γίνω εξ’ αρχής αντιληπτός ο ρόλος της είναι σημαντικός, ζωτικός θα έλεγα για το performance του SQL Server.
    Ειδικά στον SQL Server 2005 γίνεται «τρελή χρήση» της βάσης αυτής. Πολλά παλιά αλλά και νέα χαρακτηριστικά που μας έχει δώσει ο SQL Server 2005 χρησιμοποιούν την tempdb όπως:
    Query Triggers Snapshot isolation and read committed snapshot (RCSI) MARS Online index creation Temporary tables, table variables, and table-valued functions DBCC CHECK LOB parameters Cursors Service Broker and event notification XML and LOB variable Query notifications Database mail Index creation User-defined functions Στον SQL Server 2005 έχουν γίνει αρκετές βελτιώσεις στην tempdb για να έχει το μέγιστο δυνατό performace. Επίσης κάτι το οποίο θα πρέπει να επισημανθεί είναι κάθε φορά που ξεκινάει το service του SQL Server η tempdb γίνεται recreate.
    Ένα κοινό tip που όλοι γνωρίζουμε είναι το να μεταφέρουμε την tempdb σε άλλο φυσικό δίσκο και να μεγαλώνουμε το μέγεθος της από το 8ΜΒ σε κάτι που να εκπληρώνει τις ανάγκες μας. Ενδεικτικά σας παραθέτω ένα πίνακα με βάση το μέγεθος της εταιρίας
     
    Μέγεθος εταιρίας Size of Data in MB
    Size of Log in MB
    Μικρή 1024 256 Μεσαία 5120 1024 Μεγάλη 10024 2048 Ακόμα δεν θα πρέπει να έχω το option auto shrink on, καθώς επίσης να μην είναι auto expand. Για να δείτε πως μπορείτε να μεταφέρεται την tempdb σε άλλο δίσκο δείτε στα books online του SQL Server το ALTER DATABASE – EXAMPLE G. Ακόμα μερικά tips για την tempdb. Βάλτε σε ξεχωριστούς φυσικούς δίσκους τα data files και τα logs. Και γράφω τα data files και όχι το data file γιατί στην περίπτωση που είμαι σε ένα σύστημα με περισσότερους από έναν επεξεργαστές μπορώ να έχω περισσότερα από ένα data files στην tempdb, θα έλεγα μάλιστα ότι πρέπει να το κάνω διότι ο κάθε επεξεργαστής θα χρησιμοποιήσει διαφορετικό data file. Αυτό σημαίνει ότι εάν έχω 2 επεξεργαστές τότες 2 data files και αν αυτά τα έχω σε ξεχωριστούς φυσικούς δίσκους και με διαφορετικό bus, ε τότε μιλάμε για πάρτυ.
  9. antonch
    Επειδή πάντα θέλω να έχω πρόχειρα τις δυνατότητες ανά έκδοση του SQL Server για να ξέρω τι θα προτείνω στον πελάτη, και επειδή δεν βρήκα κάτι αντίστοιχο όσο και αν έψαξα, έφτιαξα αυτό το poster για να κάνω την δουλειά μου ευκολότερα και το μοιράζομαι μαζί σας.
    Θα το βρήτε εδώ.
    Ελπίζω να σας αρέσει.
  10. antonch
    Πρόσφατα με έναν συνεργάτη μου που είναι dealer μια ελληνικής εταιρίας που έχει ERP αντιμετωπίσαμε το παρακάτω πρόβλημα όταν πήγαμε να εγκαταστήσουμε τον SQL Server 2005 Standard Edition σε pc που είχε εγκατεστημένο Window XP Pro Ελληνικό.
    Σε συνεργασία μαζί του (ευχαριστώ Δημήτρη) σας παρουσιάζουμε την λύση.
    Κατά την στιγμή της εγκατάστασης του SQL Server 2005 ή 2008 παίρνουμε το παρακάτω μήνυμα λάθους στο σημείο που πάει να ενημερώσει τον MSXML Parser.

    The Windows Installer service cannot update the system file C:\WINDOWS\system32\msxml6r.dll because the file is protected by Windows. You may need to update your operating system for this program to work correctly

     
    Αυτό γίνεται διότι η εγκατάσταση του SQL Server 2005 και του 2008 πάει να γράψει στα παραπάνω αρχεία αλλά επειδή είναι File protected δεν σε αφήνει. Αυτό έχει συμβεί με την εγκατάσταση του SP3 των Windows XP Pro ελληνικά διότι η Microsoft τα έχει ενσωματώσει στον κώδικά της.
     
     
    Η λύση κατόπιν επικοινωνίας με την Microsοft είναι η ακόλουθη :
     
    Απεγκατάσταση του MSXML 6 Parser με το utility που θα βρείτε στο παρακάτω link :http://download.microsoft.com/download/e/9/d/e9d80355-7ab4-45b8-80e8-983a48d5e1bd/msicuu2.exe Κατόπιν πάμε στην Registry και στο σημείο HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon όπου βρίσκουμε την μεταβλητή SFCDisable (REG_DWORD) και από 0 την κάνουμε 1 Κάνουμε την εγκατάσταση του SQL Server (θα μας ξαναβγάλει το μήνυμα λάθους αλλά πατάμε ok) και όλα πάνε καλά. Κάνουμε restart και ελέγχουμε ξανά την registry να έχει πάλι η μεταβλητή την τιμή 1 (εάν έχει γίνει 0 την αλλάζουμε). Εγκαθιστούμε το SP2 ή το SP3 του SQL2005 και ξανακάνουμε restart. Στο τέλος ελέγχουμε την μεταβλητή στην registry να είναι 0. Το link της Microsoft για τα παραπάνω είναι το ακόλουθο : http://support.microsoft.com/kb/222473
     
    Εάν τα Windows XP Pro με SP3 είναι αγγλικά δηλαδή ίδια γλώσσα με τον SQL Server δεν ισχύουν τα παραπάνω.
  11. antonch
    Στον SQL Server 2005, και φυσικά υπάρχει και στο SQL Server 2008, πρωτοεμφανίστηκε μια νέα system database η Resource Database.
    Η database αυτή περιέχει όλα τα read-only critical system tables, metadata, και stored procedures τα οποία ο SQL Server χρειάζεται για τρέξει.
    Δεν περιέχει πληροφορίες για το SQL Server instance ή για τις databases σας, και αυτό γιατί δημιουργήται κατά την διαδικασία εγκατάστασης του SQL Server ή όταν εγκαταστήσουμε κάποιο service pack. Περιέχει δε όλα τα objects (table, stored procedures) τα οποία χρησιμοποιούμε σε όλες τις δικίες μας databases.
    H Resource Database βρήσκεται στο directory DATA που έχουμε στήσει τον SQL Server και το όνομα των αρχείων της είναι mssqlsystemresource τόσο για το .mdf όσο και για το .ldf. Εάν έχω πολλά SQL Server instances για κάθε ένα από αυτά έχω και διαφορετική Resource Database.
    Την Resource Database δεν μπορούμε να την δούμε μέσα από τον Management Studio και δεν μπορούμε να την αλλάξουμε. Σε πολύ ειδικές περιπτώσεις και μόνο με συμβουλή του Microsoft Support επιτρέπεται να γίνει κάτι τέτοιο.
    Την συγκεκριμένη database δεν την βάζουμε σε encrypted ή compressed drive, διότι αυτό μπορεί να οδήγήσει σε upgrade ή performance issues.
    Όμως ποιά είναι πρακτική αξία αυτής της system database;
    Στον SQL Server 2000 όταν κάναμε upgrade αυτόν με κάποιο patch ή service pack, παρατηρούσαμε ότι έπρεπε να τρέξουν κάποια μεγάλα scripts τα οποία στην ουσία έκαναν drop και recreate system objects. Εκτός του ότι η συγκεκριμένη διαδικασία ήταν μεγάλη σε χρόνο δεν μας έδινε την δυνατότητα να κάνουμε rollback στην προηγούμενη έκδοση που είχαμε. Στους SQL Servers 2005 & 2008 κάτι τέτοιο δεν γίνεται και αυτό γιατί είτε ρίχνουμε patch είτε service pack αυτό στην ουσία κάνει override την υπάρχουσα Resource Database. Την οποία αν την έχουμε πάρει αντίγραφο πριν την εγκατάσταση του patch ή του service pack διασφαλίζουμε την εύκολη επιστρoφή μας στην προηγούμενη έκδοση.
  12. antonch
    By Sylvia Moestl Vasilik, 2009/06/22
    Μου άρεσε πάρα πολυ και τα αναδημοσιεύω όπως έχει.
    So ... Bob's left the company to move back east, and you're the new lead database developer on the database. Or, the third-party company to which the maintenance has been outsourced is no longer working on it, so it's yours now. One way or another, you need to take over a database system that you had no part in developing. It's not in good shape, and there's not many resources for you to tap.
    What do you do?
    I've been faced with this situation a few times now, and have developed a list of some of the things that have helped me the most, both in getting productive, and in bringing the database system up to par.
    Backups
    Make sure that backups are happening. I'm assuming here that you're the database developer, and not the database administrator. However, just as minimum check, make sure that backups are occurring regularly. Ideally you should successfully restore the backup somewhere else.
    Research
    Look at the database. Go through and get an idea of the table structure, what the largest tables are by size, what the most commonly used stored procedures are, if there are jobs, and what documentation there is. Read through some the stored procedures. You may find it useful to create a quick and dirty database diagram if there isn't one, using the built in diagramming tool in SQL Server. This can also be a good visual aid when you talk to other people.
    Talk to the former developers
    This may not be an option, but try hard to have a least a few friendly interviews with the former developers. This is not the time to make comments like, "I can't believe you guys did [insert bad development practice here]". You don't know the history- maybe it was that way when they got the system. You'll want to get as much information as they can give you on current issues, items on this list, etc. Keep things friendly - and maybe try to get their cell number in case of questions. A good relationship with former developers can go a long way.
    A bug database
    Is there a bug database - somewhere that bugs (and sometimes enhancement ideas) are tracked for this system? This is certainly one of the things that you want to set up, if it's not there currently. I've always been lucky enough to work at companies where bug tracking was taken seriously, and there were systems already in place that I could just plug into. If there's no bug database, time to do some research. I wouldn't suggest reinventing the wheel here, since there's a lot of good systems out there -- just use what's available.
    Source code control
    Is the code in some kind of source code control system, such as VSS or Perforce? If it is -- is everything up to date? I'm going to hazard a guess that it's either not in source code control, or it hasn't been kept up to date. That's been a big task for me when starting work on inherited systems. There's a number of tools with which to tackle this. In the past I've used a custom written Perl tool that used SQL DMO, but I won't go into detail -- that's the topic of another article. If nothing else, you could use the built in tools that SQL Server provides to script out your database objects, and check them in. Once you have everything checked in, try running a database build from the checked in code, and compare it to production. Also -- make sure you have a good system to keep all the code updated!
    Talk to the users and/or business owners
    Sit down and have some conversations with the users. This is a good opportunity to get to know their problems and concerns, the improvements they would most like to see, and where things are heading in the future. You want to make sure that this database is sticking around, that it's not going to be replaced with a third party product or anything like that. If you're going to put a lot of work into improving the system, you need to know that your efforts are going to pay off for the business. Also-you'll probably be spending lots of time on issues that are important to a well-run database system (a bug database, source code control, etc), but that won't give them any new features. Make sure they understand this.
    Establish credibility with the users by fixing a few things or making some enhancements
    Even though you'll probably be needing to spend a lot of time on tasks like setting up source code control, bug tracking, etc, you don't want to do this exclusively. From talks with users, hopefully you've identified enhancements or bug fixes that you could get out quickly. Do what you can here. This is a great way to establish credibility with them. Let them know, too, that once you have the systems in place, bug fixes and enhancements will be much easier to roll out.
    Create a development environment
    If you don't have a development environment, but code still needs to be written, where are the developers going to write and test their code? I hate to tell you, but if they have access, they'll write and test in the production environment. So you may have stored procedures called CampaignEmailExport_TEST hanging around (and never getting deleted). Or -- oops -- you may accidentally overwrite the production version with your new version, and then it runs and causes hundreds of thousands of emails to be sent where they weren't supposed to. Not that I've ever heard of this happening. This kind of problem can go a long way towards convincing users that time and money needs to be spent on working on setting up a good foundation.
    For the development environment-you may be able to just get a backup from production, and set it up on another server. If it's too large, you might need to be creative. Whatever you do, don't develop or test in the production environment.
    Drop obsolete objects
    In a system that hasn't been maintained very well, it's likely that there are a lot of database objects out there that aren't being used. They may have suffixes like 'temp' or 'bak' on them. It can be hard to identify all of these, and you may be tempted to just leave them. However, they can cause a number of problems:
    They make it difficult to figure out what the actual working code base is. If you have a lot of duplicate, backup, "working" or "temp" objects, you don't know what your code base is like, and how complex it is. Supposed you'd like to drop a tables because it's huge, and looks like it hasn't been updated in a long time, but it turns out that they're being used by stored procedure X. If it turns out that stored procedure X is never used, but you're keeping it around in the database anyway, then you've just lost this opportunity to enhance your code because of an obsolete stored procedure. This kind of issue, multiplied by all the obsolete objects that are in the database, can cause development to be very slow, or even grind to a halt. Finally...
    There's potentially months and months of work if you start from scratch on all of the above. It'll require good judgment on what to prioritize, where to start, and how much time to spend on all the tasks that need doing. And perhaps you're not in a position to set all the priorities. But it can be worthwhile and fun to streamline and tune-up a database that just needs a little work to become a well-oiled machine, requiring much less development time.
    Thanks for reading! I welcome feedback in the form of comments, and may post an update to this article with the best suggestions and comments.
  13. antonch
    Τα User Defined Functions (UDF) είναι γνωστά στους περισσότερους. Η χρήση τους είναι μεγάλη αλλά αρκετές φορές χρησιμοποιούνται λάθος κυρίως λόγο της άγνοιας που υπάρχει γύρω από την εκτέλεση ενός UDF και ιδιαίτερα όταν αυτό εμπλέκεται μέσα σε ένα query.
    Οι περισσότεροι συγκρίνοντας το execution plan ενός query χωρίς UDF και με UDF βλέπουν ότι το query cost είναι μικρότερο σε αυτό που χρησιμοποιεί το UDF και αμέσως θεωρούν ότι αυτό είναι και το καλύτερο.
    Για ακόμα μια φορά θα τονίσω ότι δεν υπάρχει έτσι απλά καλό ή καλύτερο όλα είναι εξάρτηση από πολλούς παράγοντες όπως την ποσότητα και ποιότητα των δεδομένων των indexes κλπ
     
    http://www.sqlschool.gr/blog/sql-server-2016-new-features-the-sys-dm_exec_function_stats-dmv-1057.aspx
  14. antonch
    Καθημερινά ένας DBA ή DB developer έχει να αντιμετωπίσει αρκετούς αστάθμητους τις περισσότερες φορές παράγοντες που επηρεάζουν το performance.

    Πιστέψτε με ότι αυτό είναι μια δουλεία που απαιτεί σχολαστικότητα γνώση της αρχιτεκτονικής τόσο του SQL Server όσο και της database. Για να κάνεις αυτή την δουλεία θα πρέπει να έχει μελετήσει αρκετά και να έχεις κάνει αρκετή πρακτική εξάσκηση για την απόκτηση εμπειρίας.

    Ακόμα και ένας τέτοιος άνθρωπος πάντα επιζητά τρόπους να κάνει λιγότερο δύσκολη την δουλεία του και η χαρά του είναι μεγάλη όταν ανακαλύπτει ότι το αγαπημένο του εργαλείο έκδοση με την έκδοση του δίνει περισσότερες δυνατότητες για αυτό το task.

    http://www.sqlschool.gr/blog/sql-server-2016-new-features-the-sys-dm_exec_session_wait_stats-dmv-1056.aspx
  15. antonch
    Πάντα υπάρχει κάτι που μπορεί να σε κάνει να χαμογελάσεις ευχάριστα ακόμα και αν είναι ένα μήνυμα λάθους!.

    Κάνοντας ένα τυπικό έλεγχο σε ένα παλιό Always On Availability Group διαπίστωσα ότι ένα domain group που είχε πρόσβαση στο ένα node δεν είχε πρόσβαση στο άλλο. Φυσικά αυτό θα έπρεπε να διορθωθεί καθώς σε περίπτωση που γίνονταν failover οι χρήστες του συγκεκριμένου domain group δεν θα είχαν πρόσβαση στο άλλο.

    Τι ποιο απλό από το να κάνει κάνεις αυτή την διαδικασία είτε μέσω SSMS είτε με την εκτέλεση ενός GREATΕ LOGIN command και να βάλεις το domain group αυτό στο node που δεν υπάρχει.

    Παρόλα αυτά όμως κατά την διάρκεια της εκτέλεσης της διαδικασίας έλαβα το error message “The server principal ‘…..’ already exists – Msg 15025”, αλλά δεν υπήρχε λόγος ανησυχίας καθώς αμέσως υποψιάστηκα το τι έχει γίνει απλά έπρεπε να το επιβεβαιώσω.

    Πήγα στο node όπου το domain group υπήρχε και εκτέλεσα το παρακάτω command για να πάρω το SID του login (που επειδή είναι domain group είναι το ίδιο με το domain SID). Η SUSER_SID επιστρέφει το SID του Login που στην ουσία με αυτό δουλεύει ο SQL Server για να υλοποιήσει το security που διαθέτει.

    http://sqlschool.gr/blog/the-server-principal-already-exists-%E2%80%93-error-15025-troubleshooting-1059.aspx
×
×
  • Create New...