Presentation is loading. Please wait.

Presentation is loading. Please wait.

Effective T-SQL Solutions

Similar presentations


Presentation on theme: "Effective T-SQL Solutions"— Presentation transcript:

1 Effective T-SQL Solutions
Noah Subrin Technical Lead SRA International

2 Biography Technical Lead for SRA International
Speaker at regional Code Camps and other developer events Author of articles for (SQL Server World Wide User Group) Blog site: me at

3 Agenda How to Set Compatibility Mode Using T-SQL
How to Determine Membership in Windows Groups Using T-SQL Creating a Data Driven Web site using MySQL and VS 2008 Importing a .csv file into SQLExpress using Bulk Insert Creating a Non-Sequential Order Number System

4 How to Set Compatibility Mode Using T-SQL
Scenario – Dev team has restored a .bak file from SQL Server 2000 to SQL Server 2005 Questions about features/functionality and query plan performance How to Set/Determine Compatibility mode level This is a system stored procedure. Configurable at the database level, not at the database server level. Any new databases are created based on the compatibility mode of the model system database Functionality based on compatibility level

5 Stored Proc Syntax sp_dbcmptlevel [ = ] name ]     [ , = ] version ] Display the current level or set a new level Only the database owner, members of the sysadmin fixed server role, and the db_owner fixed database role (if you are changing the current database) can execute this procedure.

6 Compatibility Values 60 = SQL Server 6.0 65 = SQL Server 6.5

7 Implications For locking hints in the FROM clause, the WITH keyword is no longer optional Do not have access to SQL Server reserved words like PIVOT/UNPIVOT/REVERT Certain ORDER BY expressions work differently Query plans will be optimized to run under SQL Server 2005 Many other implications, reference BOL

8 Best Practices Set the target to single user access mode by using ALTER DATABASE SET SINGLE_USER. Change the compatibility level of the database to the new level Put the database in multi user access mode by using ALTER DATABASE SET MULTI_USER.

9 How to Determine Membership in Windows Groups Using T-SQL
Scenario – Dev team has done a SQL Server upgrade from SQL Server 2000 to SQL Server 2005 Server is in a managed environment where only Windows Authentication is permitted How can we tell who is a member of what Windows or Active Directory group?

10 xp_logininfo System stored procedure
In SQL Server 2005, Requires membership in the sysadmin fixed server role, or membership in the public fixed database role in the master database with EXECUTE permission granted.

11 Xp_logininfo Syntax xp_logininfo [ = ] 'account_name' ] [ , = ] 'all' | 'members' ]      [ , = ] variable_name OUTPUT]

12 What type of information is returned?
List all  members in built-in Windows groups.  List all members in an Active Directory group. Determine if an active directory user is a member of any Windows groups with access to SQL Server.

13 Result Sets Account name (Fully qualified Windows account name)
Type (user or group) Privilege (SQL Server access – admin,user, or null) Mapped login name Permission path (group membership) Column name Data type Description account name sysname Fully qualified Windows account name. type char(8) Type of Windows account. Valid values are user or group. privilege char(9) Access privilege for SQL Server. Valid values are admin, user, or null. mapped login name For user accounts that have user privilege, mapped login name shows the mapped login name that SQL Server tries to use when logging in with this account by using the mapped rules with the domain name added before it. permission path Group membership that allowed the account access.

14 Creating a Data Driven Web Site using MySQL and VS 2008
Install MySQL Install some sample data Install MySQL GUI Tools Install MySQL .Net Connector Create a new project in VS2008 Make a connection to a datasource Create a dataset and display the data

15 Importing a .csv file using Bulk Insert
SQL Server had Import/Export wizard SQL Server Management Studio Express (SSMSE) does not have the ability to do this directly How do we do this in SQL Server 2005? TSQL Bulk Insert Command Test with Excel

16 Possible Problems May need to create a file share
May have to specify UNC Path Also may have to have SQLServer service and SQL Agent run under a service account Give service account permissions to the file share

17 Creating a Non-Sequential Order Number System
Scenario: E-commerce system wishes to use a random number scheme to hide volume from the competition. We do not wish to use an identity column with an int data type that increments order numbers by one Competitor could derive volume by subtracting last order number – first number for a given day

18 Solution Concept Create a numbers table with a range that will correspond to desired order number range Select a random order number using order by newid() clause Mark value in numbers table as being used (IsUsed = 1)

19 Closing Remarks Thank you for attending
Please send me your feedback on this presentation Please feel free to contact me –


Download ppt "Effective T-SQL Solutions"

Similar presentations


Ads by Google