Tuesday, April 30, 2013

READTEXT in T-SQL (SS2012)

This statement use to read text, ntext, or image values from a text, ntext, or image column, starting from a specified offset and reading the specified number of bytes.
Parameters of statement


  • table.column
Is the name of a table and column from which to read. Table and column names must
comply with the rules for identifiers. Specifying the table and column names is required;
however, specifying the database name and owner names is optional.

  • text_ptr
Is a valid text pointer. text_ptr must be binary(16).

  • Offset
Is the number of bytes (when the text or image data types are used) or characters
(when the ntext data type is used) to skip before it starts to read the text, image, or
ntext data.

  • Size
Is the number of bytes (when the text or image data types are used) or characters
(when the ntext data type is used) of data to read. If size is 0, 4 KB bytes of data is
read.

  • HOLDLOCK
Causes the text value to be locked for reads until the end of the transaction. Other
Users can read the value, but they cannot modify it.

Thursday, February 14, 2013

Document Oriented Database

        Designed for storing, retrieving, and managing document-oriented, or semi structured data, information. Document-oriented databases are one of the main categories of so-called NoSQL databases and the popularity of the term "document-oriented database" (or "document store") has grown with the use of the term NoSQL itself. In contrast to well-known relational databases and their notions of "Relations" (or "Tables"), these systems are designed around an abstract notion of a "Document".           
 At the highest level of organization, it is quite similar to a relational database, but as you get closer to the data itself, you will notice a significant change in the way the data is stored. Instead of databases, tables, columns, and rows you have documents. A document doesn’t have a direct correlation in the relational world. Documents do not have a predefined schema like relational database tables. A document is partly a row, in that it’s where the data is located, but it's also part columns, in that the schema is defined in each document (not table-wide).

          The best way to think of a document is as a multidimensional array. In an array, you have a set of keys that map to values. The values could themselves be another array. Documents map extremely well to objects and other PHP data types like arrays and even multidimensional arrays. Documents encapsulate and encode data (or information) in some standard formats or encoding. Encoding in use include XML, YAML, JSON, and BSON, as well as binary forms like PDF and Microsoft Office documents.
           Currently lot of web based online shopping websites are moving to this kind of databases. Simple and amaizing handling with database solutions like MongoDB, Apache CouchDB , Clusterpoint etc

Sunday, January 20, 2013

Create Database Snapshot

CREATE DATABASE statement can also be used to create database snapshots of existing databases.

Database snapshot is a read only static view of a SQL Server database.Snapshot is transitionally consist with the source database as of the snapshot creation. A database snapshot always resides on the same server instances as it source database. As the source database updates the snapshot is updated.
In database snapshot creation in CREATE DATABASE statement we have to add AS SNAPSHOT OF clause in CREATE DATABASE statement others  are same as general CREATE DATABASE statement.   ( CREATE DATABASE )

Sample code :- 

Create Database in SQL Server 2012

  This example query create table named as db_name  in this case I omitted PRIMARY option and the first file is assumed as a primary file.The logical name of this file is DB_data as I mentioned in query. File name parameter is for specify physical location for the database file. db.mdf in Local disk D:  in my hard drive.

The original size of this file is 10MB ,Additional 20MB from disk may allocated by the system if it needed(FILEGROWTH).
If MAXSIZE option is not specified or it set to unlimited the file will dynamically use all space in disk as it grows.

If you need to use single transaction log file with specific logical name and destination you can use it as follows. parameters are specified are uses as same in ON category.


Full Query for create Database statement
 



Thursday, January 10, 2013

Policies Management In SQL Server

New SQL Server versions upgrade with new Declarative Management Framework (DMF) which policy based system managing one or more server instances, Databases or other Database objects called managed targets. A policy is a DMF condition together with the corresponding behavior and it can contain only one condition.

First before create policy we must have to create condition for policy.
Open SQL Server Management studio  and expand Policy Management 
  • R-Click on the condition and select New Condition
  • In wizard type condition name and choose facet that you need.In my case I want to apply this condition to all server instances therefore I choose Server Configuration from drop down menu.
  • In field select that field that you want and operator  and value as you wish.Or else you can use variable as a value. Click Ok  and create condition.

Now go to the Policies folder in Policy Management
  1. R-click Policies and select New Policy
  2. Type name and select condition from drop down Menu.
  3. In evolution field select on demand (in My Case) and make other fields as it is on default. and clock OK

To test the policy
Expand the Policy Folder and select policy that we created and Evaluate policy(In SQL Server 2008 and previous select Run now) The dialog box notifies you whether the policy fails for existing DB's.