SQL Server
SQL Server
Types of DBMS:
- Flat File Database.
- Relational Database Management system(RDBMS).
- NoSQL
Evolution of Database Management System:
Flat File Database :
• This is probably the easiest to understand but at present rarely used. You can think of this as a
single huge table. Such type of datasets were used long back in 1990s, when data was only used
to retrieve information in case of concerns. Very primitive analytics were possible on these
database.
2) DML
• Data Manipulation Language (DML) statements are used for managing data
within schema objects. Some examples:
- Select
- Insert
- Update
- Delete
- Merge
--cont--
3) DCL :
• Data Control Language (DCL) statements. Some examples:
- GRANT
- REVOKE
4) TCL
• Transaction Control (TCL) statements are used to manage the
changes made by DML statements. It allows statements to be
grouped together into logical transactions.
- COMMIT
- SAVEPOINT
- ROLLBACK
- SET TRANSACTION
Create Statement :
Create Database :
• Syntax :
CREATE DATABASE <db_Name>
(or)
Syntax
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
)
Syntax
CREATE TABLE table_name
(
column_name1 INT IDENTITY(<seed>,<increment>),
column_name2 data_type(size),
column_name3 data_type(size),
....
)
Points to Remember :
The column data type should be “Integer” , when using identity.
Defining the Seed and Increment is not mandatory by default it will assign (1,1).
Select Statement :
Syntax :
Select * From <table_name>
Select <column_name_1>, <column_name_2>, <column_name_3> From <table_name>
Select <column_name_1>,* From <table_name>
Alter Statement:
Syntax :
Points to Remember :
While changing the existing table column data type , you can not do conversion explicitly (Ex : varchar to Int)
Insert Statement:
Syntax :
INSERT INTO table_name
VALUES (value1,value2,value3,...)
Points to Remember :
You can not insert values for Identity column.
Temporary Tables :
Local Temporary Table:
• LOCAL TEMPORARY TABLES are distinct within modules and embedded SQL programs within SQL Server sessions.
• LOCAL TEMPORARY TABLES are stored in tempdb and SQL Server automatically deletes these tables when they are
no longer used.
Syntax :
CREATE TABLE #table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
)
-- cont --
Syntax :
CREATE TABLE ##table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
)
Points to remember :
You need to manually drop those temporary tables within the session (or) connection.
While using within the stored procedures it will automatically get dropped , end of the execution .
What will happen when gives more than hashes(#) for the table name ?
SQL Variables:
Local Variables :
• Must be declared.
• It should start with @
Syntax :
Declare @<variable_name> <data_type><(length)>
Global Variables :
• Global variable names begin with a @@ prefix
• You do not need to declare them, since the server constantly maintains them.
Ex :
- @@ERROR - @@IDENTITY
- @@LANGUAGE - @@ROWCOUNT
- @@SERVERNAME - @@SPID
- @@VERSION
Points to Remember :
You can assign global variables results to your local variable.
Aliases:
• COLUMN ALIASES are used to make column headings in your result set easier to read.
• TABLE ALIASES are used to shorten your SQL to make it easier to read or when you are performing a joins.
Syntax :
Select <column_name_1> AS <alias_name_a1>,<column_name_1> AS <alias_name_a2>
From <table_name>
Concatenation:
• The plus sign (+) is the string concatenation operator that enables string concatenation.
Syntax :
Select <column_name_1> + <column_name_2> AS <column_name>
From <table_name>
Points to Remember :
Concatenation is the string function , you can not use this against any other data types . If you really want to perfor concatenation against
any other data types then you need convert those column explicitly to string.
Categories of Data Types in SQL:
and scale - Exact numeric - Approximate numeric Data Types: ** Precision
- Character strings - Unicode character strings
- Date and time - Other Data Types
Exact Numeric :
Approximate Numeric :
- Float
- Real
Date And Time:
- Date Time
- Small Date Time
- Date Time 2
- Time
- Date
Non Unicode Char Strings: ** Concatenation Difference
- Char Length between 1 to 8000 - Fixed Length Data type - Takes 1 byte for each char
- Varchar Length between 1 to 8000 - Variable Length Data type - Takes 1 byte for each char
- Text Unlimited Length - Variable Length - Takes 1 byte for each char
Points to Remember :
During concatenation of CHAR data type variables, it includes space in-place of unused space in the result of
concatenation.
ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new
development work.
-- cont –
Truncate & Drop & Delete ** Drop not only for Tab & DB
Syntax :
- Truncate Table <table_name>
- Drop Table <Table_name>
- Drop Database <db_Name>
- Delete From Table Where <column_name>= <column_value>
Points to remember :
TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and
uses fewer system and transaction log resource.
Rename Statement ** Rename not only for tab,column,database
Table Rename :
Syntax :
EXCE SP_RENAME ‘<old_table_name>’ , ‘<new_table_name>’
Column Rename :
Syntax :
EXCE SP_RENAME ‘<table_name>.<old_column_name>’ , ‘<new_column_name>’,’<object_type>’
Database Rename :
Syntax:
EXEC SP_RENAME ‘<old_db_name>’,’<new_db_name>’,’<object_type>’
Points To Remember :
You need to use Appropriate database while renaming the column (or) table.
Object type is must while renaming the Database and Columns
SQL Server Functions
Aggregate Functions :
- AVG
- MIN
- MAX
- COUNT
- COUNT_BIG
- SUM
Points To Remember :
COUNT_BIG works like the COUNT function. The only difference between the two functions is their return values. COUNT_BIG
always returns a bigint data type value. COUNT always returns an int data type value.
Conversion Functions:
- CAST
- CONVERT
Cast :
SYNTAX :
CAST ([Expression] AS DataType)
Conversion :
SYNTAX :
CONVERT(data_type(length), expression, style)
Data Type Function :
- DATALENGTH -> DATALENGTH(<expression>)
- IDENT_CURRENT -> IDENT_CURRENT(‘<table_name>’)
- IDENT_INCR -> IDENT_INCR (‘<table_name>’)
- IDENT_SEED -> IDENT_SEED(‘<table_name>’)
Ranking Functions :
- DENSE_RANK()
- RANK ()
- ROW_NUMBER()
ISNULL :
Replaces NULL with the specified replacement value.
ISNULL ( check_expression,replacement_value )
NULLIF:
Returns a null value if the two specified expressions are equal. It returns the first
expression if the two expressions are not equal. NULLIF is equivalent to a searched CASE
function in which the two expressions are equal and the resulting expression is NULL.
Syntax
NULLIF ( expression1 , expression2 )
Points To Remember :
We recommend that you not use time-dependent functions. This could cause the function to be
evaluated twice and to return different results from the two invocations.
String Functions:
- UPPER
- LOWER
- LEN
- RTRIM
- LTRIM
- LEFT
- RIGHT
- REPLACE
- REVERSE
- SUBSTRING
- CHARINDEX
- STUFF
String Functions:
ORDER BY Clause
Order by is used to Sorting the query results
TOP Clause
Retrieve records from a table and limit results.
Operators in SQL ** use convert & ISNULL * Exits When subqueries
HAVING : ** Don’t use any function name as tbl name,column name and all
The SQL Server (Transact-SQL) HAVING clause is used in combination with the GROUP BY clause to restrict the groups of
returned rows to only those whose the condition is TRUE.
Syntax :
SELECT <COLUMN_NAME>,<AGGREGATE_FUNCTION>(<COLUMN_NAME>) FROM <TABLE_NAME>
GROUP BY <COLUMN_NAME>
HAVING <aggregate_function>(column_name) <operator> <Value>
UPDATE STATEMENT :
Update records in a table .
Syntax :
Update <table_name> SET <column_name> = <Value> WHERE <column_name> = <value>
Constraints in SQL:
1) Primary key constraints : ** naming con
In SQL Server (Transact-SQL), a primary key is a single field or combination of fields that uniquely defines a
record. None of the fields that are part of the primary key can contain a null value. A table can have only one
primary key.
A primary key can be defined in either a CREATE TABLE statement or an ALTER TABLE statement.
Syntax :
Create Table <table_name> (<column_name><data_type>,
<column_name><data_type>,
<column_name<data_type>,
CONSTRAINT <table_name>_pk PRIMARY KEY (<column_name>)
)
Points To Remember :
You can not alter any constraint , you need drop them and recreate if you really need any changes.
2) Foreign key constraints :
A foreign key is a way to enforce referential integrity within your SQL Server database. A foreign key means that
values in one table must also appear in another table.
The referenced table is called the parent table while the table with the foreign key is called the child table. The
foreign key in the child table will generally reference a primary key in the parent table.
Syntax :
Create Table <table_name> (<column_name><data_type>,
<column_name><data_type>,
<column_name<data_type>,
CONSTRAINT <table_name>_fk FOREIGN KEY (<column_name>)
REFERENCES <table_name> (<column_name>)
)
Points To Remember :
The Primary Key and Foreign Key references will not work with Global and Local Temporary tables.
3) Check constraints :
A check constraint in SQL Server (Transact-SQL) allows you to specify a condition on each row in a table.
Syntax :
Create Table <table_name> (<column_name><data_type>,
<column_name><data_type>,
<column_name<data_type>,
CONSTRAINT chk_<name>
CHECK (column_namn <condition>)
)
Points To Remember :
A check constraint can NOT be defined on a SQL View.
The check constraint defined on a table must refer to only columns in that table. It can not refer to columns
in other tables.
A check constraint can NOT include a Sub query.
Working with Sub queries : ** Not IN with NULL
In SQL Server, a subquery is a query within a query. You can create subqueries within your SQL statements.
These subqueries can reside in the WHERE clause, the FROM clause, or the SELECT clause.
Syntax :
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column
LEFT OUTER JOIN
This type of join returns all rows from the LEFT-hand table specified in the ON condition and only those rows
from the other table where the joined fields are equal (join condition is met).
Syntax :
SELECT columns
FROM table1
LEFT [OUTER] JOIN table2
ON table1.column = table2.column;
RIGHT OUTER JOIN
This type of join returns all rows from the RIGHT-hand table specified in the ON condition and only those rows
from the other table where the joined fields are equal (join condition is met).
Syntax :
SELECT columns
FROM table1
RIGHT [OUTER] JOIN table2
ON table1.column = table2.column;;
FULL OUTER JOIN
This type of join returns all rows from the LEFT-hand table and RIGHT-hand table with nulls in place where the
join condition is not met.
Syntax :
SELECT columns
FROM table1
FULL [OUTER] JOIN table2
ON table1.column = table2.column;
SELF JOIN
A self join is a join in which a table is joined with itself (which is also called Unary relationships), specially when
the table has a FOREIGN KEY which references its own PRIMARY KEY. To join a table itself means that each row
of the table is combined with itself and with every other row of the table.
The self join can be viewed as a join of two copies of the same table. The table is not actually copied, but SQL
performs the command as though it were.
The syntax of the command for joining a table to itself is almost same as that for joining two different tables. To
distinguish the column names from one another, aliases for the actual the table name are used, since both the
tables have same name. Table name aliases are defined in the FROM clause of the SELECT statement. See the
syntax :
Syntax :
The common table expression (CTE) is a temporary named result set that you can reference within a SELECT,
INSERT, UPDATE, or DELETE statement. You can also use a CTE in a CREATE VIEW statement, as part of the
view’s SELECT query. In addition, as of SQL Server 2008, you can add a CTE to the new MERGE statement.
Syntax :
Types Of CTE :
Nonrecursive
Recursive
CASE WHEN CONDTION :
The CASE statement is SQL’s way of handling if/then logic. The CASE statement is followed by at least one pair of
WHEN and THEN statements—SQL’s equivalent of IF/THEN in Excel. It must end with the END statement. The ELSE
statement is optional, and provides a way to capture values not specified in the WHEN/THEN statements. CASE is
easiest to understand in the context syntax.
Syntax :
CASE expression
WHEN value_1 THEN result_1
WHEN value_2 THEN result_2
WHEN value_n THEN result_n
ELSE result
END
IF ELSE STATEMENT :
In SQL Server, you use a WHILE LOOP when you are not sure how many times you will execute the loop body and
the loop body may not execute even once.
Syntax :
IF condition
{...statements to execute when condition is TRUE...}
[ELSE
{...statements to execute when condition is FALSE...} ]
WHILE LOOP :
In SQL Server, you use a WHILE LOOP when you are not sure how many times you will execute the loop body and
the loop body may not execute even once.
Syntax :
WHILE condition
BEGIN
{...statements...}
END
VIEWS :
A VIEW, in essence, is a virtual table that does not physically exist in SQL Server. Rather, it is created by a query
joining one or more tables.
Syntax :
POINTS TO REMEMBER :
PIVOT
PIVOT is one of the new relational operator introduced in Sql Server 2005. It provides an easy mechanism in Sql
Server to transform rows into columns.
Syntax :
SELECT <non-pivoted column>,
[first pivoted column] AS <column name>,
[second pivoted column] AS <column name>,
...
[last pivoted column] AS <column name>
FROM
(<SELECT query that produces the data>)
AS <alias for the source query>
PIVOT
(
<aggregation function>(<column being aggregated>)
FOR
[<column that contains the values that will become column headers>]
IN ( [first pivoted column], [second pivoted column],
... [last pivoted column])
) AS <alias for the pivot table>
<optional ORDER BY clause>;
POINTS TO REMEMBER :
When aggregate functions are used with PIVOT, the presence of any null values in the value column are
not considered when computing an aggregation.
UNPIVOT
UNPIVOT is almost reversal of the PIVOT operation. It basically provides a mechanism for transforming columns
into rows.
Stored Procedures:
A stored procedure in SQL Server is a group of one or more Transact-SQL statements, its
stored in SQL Server. Storing the code inside the SQL Server object gives us many advantages.
• Reduced server/client network traffic
• Stronger security
• Reuse of code
• Easier maintenance
• Improved performance
Types:
• User-defined
• System
• Ex: SP_Helptext , sp_who2
• Extended User-Defined
• XP_fixeddrives
Stored Procedures:
Syntax:
1. Create:
Create Procedure Procedure-name
(
@ParameterName datatype , -- Input parameter
@ParameterName datatype out -- Output Parameters (If required)
)
As
Begin
Sql statement used in the stored procedure
End
2. Alter
Alter Procedure Procedure-name
(
@ParameterName datatype , -- Input parameter
@ParameterName datatype out -- Output Parameters (If required)
)
As
Begin
Sql statement used in the stored procedure
End
3. Drop
Stored Procedures:
Examples:
EXEC Getstudentname 1
Stored Procedures:
Examples:
/* GetstudentnameInOutputVariable is the name of the stored procedure which uses output variable
@Studentname to collect the student name returns by the stored procedure*/
Create PROCEDURE GetstudentnameInOutputVariable
(
@studentid INT, --Input parameter , Studentid of the student
@studentname VARCHAR(200) OUT -- Out parameter declared with the help of OUT keyword
)
AS
BEGIN
SELECT @studentname= Firstname+' '+Lastname FROM tbl_Students WHERE studentid=@studentid
END
Views:
Creates a virtual table whose contents (columns and rows) are
defined by a query. Use this statement to create a view of the data in one or more
tables in the database.
Purposes:
• To focus, simplify, and customize the perception each user has of the database.
• As a security mechanism by allowing users to access data through the view, without granting
the users permissions to directly access the underlying base tables.
• To provide a backward compatible interface to emulate a table whose schema has changed.
CURSOR :
Microsoft SQL Server statements produce a complete result set, but there are times when the results
are best processed one row at a time. Opening a cursor on a result set allows processing the result set one row
at a time.
Syntax:
DECLARE cursor_name CURSOR
[LOCAL | GLOBAL] --define cursor scope
[FORWARD_ONLY | SCROLL] --define cursor movements (forward/backward)
[STATIC | KEYSET | DYNAMIC | FAST_FORWARD] --basic type of cursor
[READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] --define locks
FOR select_statement --define SQL Select statement
FOR UPDATE [col1,col2,...coln] --define columns that need to be updated
POINTS TO REMEMBER :
You cannot use cursors or triggers on a table with a clustered columnstore index. This restriction does not
apply to nonclustered columnstore indexes; you can use cursors and triggers on a table with a nonclustered
index.
TRIGGERS :
A trigger is a special kind of a store procedure that executes in response to certain action on the table like
insertion, deletion or updating of data. It is a database object which is bound to a table and is executed
automatically. You can’t explicitly invoke triggers. The only way to do this is by performing the required action
no the table that they are assigned to.
Types Of Triggers
• After Triggers (For Triggers)
• Instead Of Triggers
Syntax:
CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH <dml_trigger_option> [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
FUNCTIONS :
Function is a database object in Sql Server. Basically it is a set of sql statements that accepts
only input parameters, perform actions and return the result. Function can return only single value or a table.
We can’t use function to Insert, Update, Delete records in the database table(s).
Types:
• System Defined Function
• User Defined Function
The plan for a SQL statement is a set of instructions. This tells the database how to
access the data and join it together.
Estimated
An estimated execution plan is generated without actually executing the
query. It is based on available statistics on indexes.
Actual
An actual execution plan is generated after executing the query. It is more
informative and reliable as it is based on actual execution not on estimated
statistics.
Estimated VS Actual :
Important operators of execution plan:
Table scan
Index seek
Index scan
RID Lookup
Key lookup
Statistics IO:
Set statistics IO on
Table scan :
It looks each and every row at the table and bring out the
expected results from database tables.
Index scan :
It looks only the index at the table and bring out the expected
results from database tables.
Index seek :
It looks index and as well as the given inputs but completely
through the index.
OpenXML
• SQL Server 2000 provides a system-defined function, OpenXML, that creates Rowsets from XML
documents.
• OPENXML allows the data in XML document to be treated just like the columns and rows of your
database table
• The OPENXML function allows developers to parse XML data so that it can be stored as relational data in
tabular form. This function supports the XML data type and the sp_xml_preparedocument system
stored procedure accepts this new data type. This procedure is used by OPENXML function.
• Inserting from XML is faster when using openxml
• OPENXML provides an easy way to use an XML document as a data-source for your procedures.
POINTS TO REMEMBER :
OPENXML is very memory intensive. The pointer returned by the system stored procedure
sp_xml_preparedocument is a memory pointer to a COM XML document object model. So, you must be careful
not to load very large XML documents into memory with OPENXML because it may overload your server's
memory.
OpenXML
Example:
DECLARE @h int
DECLARE @xmldoc VARCHAR(1000)
--xmldoc is set with the xml elements which are to be inserted into the table students with FirstName,
ID,Technology as table columns
SET @xmldoc =
'<root>
<student FirstName="Ravi" ID="1" Technology="DotNet"></student>
<student FirstName="Avdesh" ID="2" Technology="DotNet"></student> </root>'
EXEC sp_xml_preparedocument @h OUTPUT, @xmldoc
--This sp_xml_preparedocument is internal server SP (pseudo SP). which takes the xmldoc as input and
gives an output in @h which contains the data which is to be manipulated further
INSERT INTO student
SELECT * FROM OpenXML(@h,'/root/student')
WITH student
EXEC sp_xml_removedocument @h
--sp_xml_removedocument free's up the memory.
Transactions
A transaction is a single unit of work. If a transaction is successful, all of the data modifications
made during the transaction are committed and become a permanent part of the database. If a
transaction encounters errors and must be canceled or rolled back, then all of the data modifications
are erased.
Syntax:
BEGIN { TRAN | TRANSACTION }
[ { transaction_name | @tran_name_variable }
[ WITH MARK [ 'description' ] ] ] [ ; ]
Index
• An index is an on-disk structure associated with a table or views that
speed retrieval of rows from the table or view. An index contains keys
built from one or more columns in the table or view. These keys are
stored in a structure (B-tree) that enables SQL Server to find the row
or rows associated with the key values quickly and efficiently.
Types:
1. Clustered
2. Non-Clustered
Clustered index
• Clustered indexes sort and store the data rows in the table or view
based on their key values. These are the columns included in the
index definition. There can be only one clustered index per table,
because the data rows themselves can be sorted in only one order.
• The only time the data rows in a table are stored in sorted order is
when the table contains a clustered index. When a table has a
clustered index, the table is called a clustered table. If a table has no
clustered index, its data rows are stored in an unordered structure
called a heap.
Syntax:
CREATE CLUSTERED INDEX Index Name ON Tablename (columnname)
Non-clustered index
• Nonclustered indexes have a structure separate from the data rows. A
nonclustered index contains the nonclustered index key values and each key
value entry has a pointer to the data row that contains the key value.
• The pointer from an index row in a nonclustered index to a data row is called
a row locator. The structure of the row locator depends on whether the data
pages are stored in a heap or a clustered table. For a heap, a row locator is a
pointer to the row. For a clustered table, the row locator is the clustered
index key.
Syntax:
CREATE NON CLUSTERED INDEX Index Name ON Tablename (columnname)
SQL Server Profiler
SQL Server Profiler is an interface to create and manage traces and analyze and
replay trace results. Events are saved in a trace file that can later be analyzed or used to
replay a specific series of steps when trying to diagnose a problem.
• Sp_help
• sp_helpdb
• Sp_helptext
• Sp_depends
• sp_helpfile
• sp_spaceused
• sp_who
• sp_lock
• sp_configure
• sp_tables
• sp_columns
• sp_depends
Security
• Credentials
• Users
• Roles
Linked Servers
Linked Servers
Linked Servers
Linked Servers
Linked Servers
Linked Servers
Linked Servers
Linked Servers
Partitioned Tables and Indexes
SQL Server supports table and index partitioning. The data
of partitioned tables and indexes is divided into units that can be
spread across more than one filegroup in a database. The data is
partitioned horizontally, so that groups of rows are mapped into
individual partitions. All partitions of a single index or table must reside
in the same database. The table or index is treated as a single logical
entity when queries or updates are performed on the data.
Partitioned Tables
Database table partitioning is the process where very large tables are divided into multiple parts. The
data in partitioned tables is horizontally divided into units that can be spread across more than one filegroup
in a database.
Partitioning can make large tables more manageable and scalable. The main of goal of partitioning is to
aid in maintenance of large tables and to reduce the overall response time to read and load data for particular
SQL operations
• What is filegroup: Database objects and files can be grouped together in filegroups for allocation and
administration purposes. There are two types of filegroups:
• Primary file group: The primary filegroup contains the primary data file and any other files not specifically
assigned to another filegroup. All pages for the system tables are allocated in the primary filegroup.
• User-defined file group: User-defined filegroups are any filegroups that are specified by using the
FILEGROUP keyword in a CREATE DATABASE or ALTER DATABASE statement.
Partitioned Tables
Syntax:
USE AdventureWorks2012;
GO
-- Adds four new filegroups to the AdventureWorks2012 database
ALTER DATABASE AdventureWorks2012
ADD FILEGROUP test1fg;
GO
ALTER DATABASE AdventureWorks2012
ADD FILEGROUP test2fg;
GO
ALTER DATABASE AdventureWorks2012
ADD FILEGROUP test3fg;
GO
ALTER DATABASE AdventureWorks2012
Partitioned Tables
Syntax:
-- Creates a partition function called myRangePF1 that will partition a table into four partitions
CREATE PARTITION FUNCTION myRangePF1 (int)
AS RANGE LEFT FOR VALUES (1, 100, 1000) ;
GO
-- Creates a partition scheme called myRangePS1 that applies myRangePF1 to the four filegroups created
above
CREATE PARTITION SCHEME myRangePS1
AS PARTITION myRangePF1
TO (test1fg, test2fg, test3fg, test4fg) ;
GO
-- Creates a partitioned table called PartitionTable that uses myRangePS1 to partition col1
CREATE TABLE PartitionTable (col1 int PRIMARY KEY, col2 char(10))
ON myRangePS1 (col1) ;
Partitioned Index
Syntax:
CREATE PARTITION FUNCTION PF(INT) AS RANGE FOR VALUES (0, 10, 100)
CREATE PARTITION SCHEME PS AS PARTITION PF ALL TO ([PRIMARY])