DBA Developer
Responsibilities Designing Relational databases Developing interface layer Environment Microsoft SQL Server,.NET SQL Layer: Stored procedures, functions,CLR Objects Object Layer: ADO. Net, Microsoft enterprise library, Object-Relational mappers Query optimization/Performance tuning Code review for performance Missing indices
Applications Single Sign on (SSO) Search Solutions Search Database Search Engines Import/Export solutions Sending to and receiving data from web services XML/CSV transformation Frameworks Data warehouse and OLAP
Challenges Performance Missing index Poorly written queries Normalized vs. Denormalized Deadlocks Design Schema flexible to changes DDL (data definition language) Vs DML(data manipulation language) ○ example
Simple example Design a database to store user information Username,password, first name, last name, postal code Requirement changes , Address, City, Province, Country, language and etc now is needed to be stored. Solution ? CREATE TABLE Users ( UserID INT NOT NULL Primary Key, UserName NVARCHAR(50) NOT NULL, FirstName NVARCHAR(50) NULL, LastName NVARCHAR(50) NULL, PostalCode NVARCHAR(50) NULL );
Simple example Option 1 add more column to the Users table Option 2 insert rows instead of columns (How)
CREATE TABLE Users ( UserID INT NOT NULL Primary Key, UserName NVARCHAR(50) NOT NULL ); CREATE TABLE Properties ( PropertyID INT NOT NULL Primary Key, PropertyName NVARCHAR(50) NOT NULL ) CREATE TABLE UserProperty ( PropertyID INT NOT NULL Primary Key, UserID INT NOT NULL, value NVARCHAR(100) NOT NULL ) Many to Many Relation
XML DataType –Hybrid design CREATE TABLE Users ( UserID INT NOT NULL Primary Key, UserName NVARCHAR(50) NOT NULL, UserProperty XML ); CREATE TABLE Properties ( PropertyID INT NOT NULL Primary Key, PropertyName NVARCHAR(50) NOT NULL ) CREATE TABLE UserProperty ( PropertyID INT NOT NULL Primary Key, UserID INT NOT NULL, value NVARCHAR(100) NOT NULL )
XML DataType –Hybrid design XML Advantages Flexibility Easy to parse and to serialized in to objects Disadvantages Searching trough XML is Slow Maintenance – adds over head to insert and update XML model is not a replacement for Relational model
Good to know about Paging in SQL Trees & Hierarchies in SQL Graph in SQL Recursive query in SQL (using Common Table Expressions) XML manipulation (XPATH,XQUERY) CLR objects in MS SQL Server