Monday, January 12, 2009

.Net Configurations-Application level,Machine level,Security Level

Application Configuration File:This configuration file is used to set the settings for single application.It is application level configuration file.Any changes made to application configuration file will applicable to only single application.

Machine Configuration : This configuration file is used to set the settings for a resource that is used by multiple applications.The machine.config file is located in C:\\Microsoft.NET\Framework\\config\machine.config.This is a system level configuration file.Any changes made to this file will applicable for all applications that are located in that system
Security Configuration File:
Security configuration files contain information about the code group hierarchy and permission sets associated with a policy level. It is strongly recommended that you use the .NET Framework Configuration tool (Mscorcfg.msc) or Code Access Security Policy tool (Caspol.exe) to modify security policy to ensure that policy changes do not corrupt the security configuration files.

SQL Server Functions

Functions : Creates a user-defined function, which is a saved Transact-SQL routine that returns a value. User-defined functions cannot be used to perform a set of actions that modify the global database state. User-defined functions, like system functions, can be invoked from a query. They also can be executed through an EXECUTE statement like stored procedures.
Types Of Functions:
  1. Row set functions :Can be used like table references in an SQL statement.
  2. Aggregate functions :Operate on a collection of values but return a single, summarizing value.
  3. Scalar functions :Operate on a single value and then return a single value. Scalar functions can be used wherever an expression is valid. This table categorizes the scalar functions.

SQL Server Function Categories:

  1. Configuration Functions:Returns information about the current configuration.
  2. Cursor Functions:Returns information about cursors.
  3. DateandTimeFunctions:DATEADD ,DATEDIFF,DATENAME,DATEPART,DAY ,GETDATE ,GETUTCDATE ,MONTH,YEAR
    Performs an operation on a date and time input value and returns either a string, numeric, or date and time value.
  4. Mathematical Functions:performs a calculation based on input values provided as parameters to the function, and returns a numeric value.
  5. Metadata Functions:Returns information about the database and database objects.
  6. Security Functions:Returns information about users and roles.
  7. String Functions:Performs an operation on a string (char or varchar) input value and returns a string or numeric value.
  8. System Functions:Performs operations and returns information about values, objects, and settings in Microsoft SQL Server.
  9. System Statistical Functions:Returns statistical information about the system.
  10. Text and Image Functions: Performs an operation on a text or image input values or column, and returns information about the value.

Functions Behaviour:UDF's support a wide range of functionality and just because you can’t commit write changes to a database, it doesn't mean that you should turn a blind eye to them. Here's a list of the statements that you can include in the body of a UDF

  • Flow control statements such as IF…ELSE, CASE, GOTO labels, etc.
  • UPDATE, INSERT and DELETE commands to modify the contents of tables which are local to the UDF and have been created using SQL Server 200's news TABLE variable type.
  • The EXECUTE command to execute stored procedures and extended stored procedures.
  • The SET and SELECT statements to assign a value to a variable.
  • SELECT statements to retrieve field values from tables into local variables.
  • CURSOR, OPEN CURSOR, CLOSE CURSOR, DEALLOCATE CURSOR and FETCH NEXT FROM statements as long as the cursor is both created and disposed of within the scope of the UDF. Note that actual rows can't be returned, and they must be explicitly returned into type-matching variables using the FETCH NEXT INTO statement.
  • DECLARE statements to create variables local (in terms of scope) to the UDF.
    Internally defined SQL variables which are prepended with "@@", such as @@ERROR and @@FETCH_STATUS.

Function and Stored Procedures Comparision:

  • Scope of modification: UDF's aren't allowed to modify the physical state of a database using INSERT, UPDATE or DELETE statements. They can only work with local data.
  • Output parameters: UDF's don't have the ability to return output parameters to the calling function. They do however let us return a single scalar value or a locally created table.
  • Error handling: In UDF's, if an error occurs during a call to a stored procedure or a trigger, then that statement is terminated and flow control continue through the UDF.
  • Calling conventions: One of the major differences between UDF's and stored procedures is that a UDF can be called through a SQL statement without using the EXECUTE statement

Creating Scalar Function:

CREATE FUNCTION dbo.mult(@num1 INT,@num2 INT)

RETURNS INT

AS

BEGIN

RETURN (@num1 * @num2)

END


Creating Table Valued Function :

CREATE FUNCTION getAuthorsByState(@state CHAR(2) )

RETURNS TABLE

AS

RETURN(SELECT au_fname + ' ' + au_lname AS NameFROM authorsWHERE state = @state)

Friday, January 9, 2009

SQL Server Cursors

Cursors :
These let you move through rows one at a time and perform processing on each row
Cursors Keywords:

  • The DECLARE CURSOR statement defines the SELECT statement that forms the basis of the cursor.
  • The OPEN statement executes the SELECT statement and populates the result set.
  • The FETCH statement returns a row from the result set into the variable. You can select multiple columns and return them into multiple variables.
  • The variable @@FETCH_STATUS is used to determine if there are any more rows. It will contain 0 as long as there are more rows. We use a WHILE loop to move through each row of the result set.
  • cursor_name - The name of the server side cursor, must contain from 1 to 128 characters.

    Types Of Cursors:
  • LOCAL - Specifies that cursor can be available only in the batch, stored procedure, or trigger in which the cursor was created. The LOCAL cursor will be implicitly deallocated when the batch, stored procedure, or trigger terminates.
  • GLOBAL - Specifies that cursor is global to the connection. The GLOBAL cursor will be implicitly deallocated at disconnect.
  • FORWARD_ONLY - Specifies that cursor can only fetch data sequentially from the first to the last row. FETCH NEXT is the only fetch option supported.
  • STATIC - Specifies that cursor will use a temporary copy of the data instead of base tables. This cursor does not allow modifications and modifications made to base tables are not reflected in the data returned by fetches made to this cursor.
  • KEYSET - Specifies that cursor uses the set of keys that uniquely identify the cursor's rows (keyset), so that the membership and order of rows in the cursor are fixed when the cursor is opened. SQL Server uses a table in tempdb to store keyset. The KEYSET cursor allows updates nonkey values from being made through this cursor, but inserts made by other users are not visible. Updates nonkey values made by other users are visible as the owner scrolls around the cursor, but updates key values made by other users are not visible. If a row is deleted, an attempt to fetch the row returns an @@FETCH_STATUS of -2.
  • DYNAMIC - Specifies that cursor reflects all data changes made to the base tables as you scroll around the cursor. FETCH ABSOLUTE option is not supported with DYNAMIC cursor.
  • FAST_FORWARD - Specifies that cursor will be FORWARD_ONLY and READ_ONLY cursor. The FAST_FORWARD cursors produce the least amount of overhead on SQL Server.
  • READ ONLY - Specifies that cursor cannot be updated.
  • SCROLL_LOCKS - Specifies that cursor will lock the rows as they are read into the cursor to ensure that positioned updates or deletes made through the cursor will be succeed.
  • OPTIMISTIC - Specifies that cursor does not lock rows as they are read into the cursor. So, the positioned updates or deletes made through the cursor will not succeed if the row has been updated outside the cursor since this row was read into the cursor.
  • TYPE_WARNING - Specifies that if the cursor will be implicitly converted from the requested type to another, a warning message will be sent to the client.
    SELECT_STATEMENT - The standard select statement, cannot contain COMPUTE, COMPUTE BY, FOR BROWSE, and INTO keywords.
  • UPDATE - Specifies that all cursor's columns can be updated (if OF column_name [,...n] is not specified), or only the columns listed in the OF column_name [,...n] list allow modifications

Optimization Tips:

  • Try to avoid using SQL Server cursors whenever possible.
    Using SQL Server cursors can result in some performance degradation in comparison with select statements. Try to use correlated subquery or derived tables if you need to perform row-by-row operations.
  • Do not forget to close SQL Server cursor when its result set is not needed.
    To close SQL Server cursor you can use the CLOSE {cursor_name} command. This command releases the cursor result set and frees any cursor locks held on the rows on which the cursor is positioned.
  • Do not forget to deallocate SQL Server cursor when the data structures comprising the cursor are not needed.
    To deallocate SQL Server cursor, you can use the DEALLOCATE {cursor_name} command. This command removes a cursor reference and releases the data structures comprising the cursor.
  • Try to reduce the number of records to process in the cursor.
    To reduce the cursor result set, use the WHERE clause in the cursor's select statement. It can increase cursor performance and reduce SQL Server overhead.
  • Try to reduce the number of columns to process in the cursor.
    Include in the cursor's select statement only necessary columns. It will reduce the cursor result set. So, the cursor will use fewer resources. This can increase cursor performance and reduce SQL Server overhead.
  • Use READ ONLY cursors, whenever possible, instead of updatable cursors.
    Because using cursors can reduce concurrency and lead to unnecessary locking, try to use READ ONLY cursors, if you do not need to update cursor result set.
    Try avoid using insensitive, static and keyset cursors, whenever possible.
    These types of cursor produce the largest amount of overhead on SQL Server as they cause a temporary table to be created in TEMPDB, which results in some performance degradation.
  • Use FAST_FORWARD cursors, whenever possible.
    The FAST_FORWARD cursors produce the least amount of overhead on SQL Server as they are read-only cursors and can only be scrolled from the first to the last row. Use FAST_FORWARD cursor if you do not need to update cursor result set and the FETCH NEXT will be the only used fetch option.
  • Use FORWARD_ONLY cursors, if you need updatable cursor and the FETCH NEXT will be the only used fetch option.
    If you need read-only cursor and the FETCH NEXT will be the only used fetch option, try to use FAST_FORWARD cursor instead of FORWARD_ONLY cursor. By the way, if one of the FAST_FORWARD or FORWARD_ONLY is specified, the other cannot be specified



Use Case Scenario's:

  • Reporting - Based on the design of the reports and the underlying design, cursors are typically not needed
  • Serialized processing - If you have a need to complete a process in serialized manner, cursors are a viable option.
  • Administrative tasks - Many administrative tasks need to be executed in a serial manner, which fits nicely into cursor based logic, but other system based objects exist to fulfill the need. In some of those circumstances, cursors are used to complete the process.
  • Large data sets - With large data sets you could run into any one or more of the following:
    Cursor based logic may not scale to meet the processing needs.
  • With large set based operations on servers with a minimal amount of memory, the data may be paged or monopolize the SQL Server which is time consuming can cause contention and memory issues. As such, a cursor based approach may meet the need.
  • Some tools inherently cache the data to a file under the covers, so processing the data in memory may or may not actually be the case.
  • If the data can be processed in a staging SQL Server database the impacts to the production environment are only when the final data is processed. All of the resources on the staging server can be used for the ETL processes then the final data can be imported.
    SSIS supports batching sets of data which may resolve the overall need to break-up a large data set into more manageable sizes and perform better than a row by row approach with a cursor.
  • Depending on how the cursor or SSIS logic is coded, it may be possible to restart at the point of failure based on a checkpoint or marking each row with the cursor. However, with a set based approach that may not be the case until an entire set of data is completed. As such, troubleshooting the row with the problem may be more difficult

Cursor Options and Related Stored Procedures:

  • sp_cursor_list : Returns a list of cursors currently visible on the connection and their attributes.
  • sp_describe_cursor : Describes the attributes of a cursor, such as whether it is a forward-only or scrolling cursor.
  • sp_describe_cursor_columns : Describes the attributes of the columns in the cursor result set.sp_describe_cursor_tables Describes the base tables accessed by the cursor.
  • Options
  • FETCH FIRST: Fetches the first row in the cursor.
  • FETCH NEXT: Fetches the row after the previously fetched row.
  • FETCH PRIOR: Fetches the row before the previously fetched row.
  • FETCH LAST: Fetches the last row in the cursor
  • FETCH ABSOLUTE n: If n is a positive integer, it fetches the nth row in a cursor. If n is a negative integer, it fetches the nth row before the last row. If n is 0, no row is fetched.
  • FETCH RELATIVE n: If n is positive, it fetches the nth row from the previously fetched row. If n is negative, it fetches the nth row before the previously fetched row.If n is 0, the same row is fetched again.

Example 1:

Declare Flight_cursor CURSOR SCROLL

FOR SELECT * from flight Order By Aircraft_code

Open Flight_Cursor

Fetch First From Flight_Cursor

While @@Fetch_Status =0

BEGIN

Fetch NExt from Flight_Cursor

End

Example 2:

Declare @@counter int

set @@counter=0

Declare @@ProductID int

Declare @@ProductName varchar(30)

Declare @@Qty int
Declare special cursorlocal

Scroll Keyset Optimistic

ForSelect * from Products

Open special /* Opening the cursor */

fetch Absolute 1 from special into @@ProductID,@@ProductName,@@Qty
while @@fetch_Status<>-1

begin

fetch next from specialinto @@ProductID,@@ProductName,@@QtyPrint @@ProductiDPrint @@ProductNameprint @@Qty
/*set @@ProductName=(Select Prod_Name from special)*/

Update Products set Prod_Name= @@counter
set @@counter=@@counter+1

end

close special

Deallocate special

Cursor Locks:

READ ONLY: This prevents any updates on the table.

SCROLL LOCK: This allows you to make changes to the table.

OPTIMISTIC: This checks if any change in the table record since the row fetched before updating. If there is no change, the cursor can update

Thursday, January 8, 2009

SQL Server Views

What is View:


  • A view is a virtual table that consists of columns from one or more tables. Though it is similar to a table, it is stored in the database.
  • It is a query stored as an object. Hence, a view is an object that derives its data from one or more tables. These tables are referred to as base or underlying tables.
  • Once you have defined a view, you can reference it like any other table in a database.

Scenarios and Behaviour:

  • A view serves as a security mechanism. This ensures that users are able to retrieve and modify only the data seen by them.
  • Users cannot see or access the remaining data in the underlying tables. A view also serves as a mechanism to simplify query execution.
  • Complex queries can be stored in the form as a view, and data from the view can be extracted using simple queries.
  • Ensure the security of data by restricting access to the following data:
  • Specific rows of the tables.
  • Specific columns of the tables.
  • Specific rows and columns of the tables.
  • Rows fetched by using joins.
  • Statistical summary of data in a given tables.

Creating View:

CREATE VIEW MyView AS

SELECT CustomerId, Company Name FROM Customers

Accessing View Data:

select * from MyView

Scenarios for Using Views:

  • Views are generally used to focus, simplify, and customize the perception each user has of the database. Views can be used as security mechanisms by allowing users to access data through the view, without granting the users permissions to directly access the underlying base tables of the view. Views can also be used, when copying data to and from Microsoft® SQL Server™ 2000, to improve performance and to partition data.
    To Focus on Specific Data
  • Views allow users to focus on specific data that interests them and on the specific tasks for which they are responsible. Unnecessary data can be left out of the view. This also increases the security of the data because users can see only the data that is defined in the view and not the data in the underlying table. For more information about using views for security purposes
  • To Simplify Data Manipulation
    Views can simplify how users manipulate data. You can define frequently used joins, projections, UNION queries, and SELECT queries as views so that users do not have to specify all the conditions and qualifications each time an additional operation is performed on that data. For example, a complex query that is used for reporting purposes and performs subqueries, outer joins, and aggregation to retrieve data from a group of tables can be created as a view. The view simplifies access to the data because the underlying query does not have to be written or submitted each time the report is generated; the view is queried instead. For more information about manipulating data.
    You can also create inline user-defined functions that logically operate as parameterized views, or views that have parameters in WHERE-clause search conditions.
    To Customize Data
  • Views allow different users to see data in different ways, even when they are using the same data concurrently. This is particularly advantageous when users with many different interests and skill levels share the same database. For example, a view can be created that retrieves only the data for the customers with whom an account manager deals. The view can determine which data to retrieve based on the login ID of the account manager who uses the view.
    To Export and Import Data:
  • Views can be used to export data to other applications. For example, you may want to use the stores and sales tables in the pubs database to analyze sales data using Microsoft® Excel. To do this, you can create a view based on the stores and sales tables. You can then use the bcp utility to export the data defined by the view. Data can also be imported into certain views from data files using the bcp utility or BULK INSERT statement providing that rows can be inserted into the view using the INSERT statement. For more information about the restrictions for copying data into views
  • The Transact-SQL UNION set operator can be used within a view to combine the results of two or more queries from separate tables into a single result set. This appears to the user as a single table called a partitioned view. For example, if one table contains sales data for Washington, and another table contains sales data for California, a view could be created from the UNION of those tables. The view represents the sales data for both regions.
  • To use partitioned views, you create several identical tables, specifying a constraint to determine the range of data that can be added to each table. The view is then created using these base tables. When the view is queried, SQL Server automatically determines which tables are affected by the query and references only those tables.
  • For example, if a query specifies that only sales data for the state of Washington is required, SQL Server reads only the table containing the Washington sales data; no other tables are accessed.
  • Partitioned views can be based on data from multiple heterogeneous sources, such as remote servers, not just tables in the same database. For example, to combine data from different remote servers each of which stores data for a different region of your organization, you can create distributed queries that retrieve data from each data source, and then create a view based on those distributed queries.
  • Any queries read only data from the tables on the remote servers that contains the data requested by the query; the other servers referenced by the distributed queries in the view are not accessed.
  • When you partition data across multiple tables or multiple servers, queries accessing only a fraction of the data can run faster because there is less data to scan. If the tables are located on different servers, or on a computer with multiple processors, each table involved in the query can also be scanned in parallel, thereby improving query performance. Additionally, maintenance tasks, such as rebuilding indexes or backing up a table, can execute more quickly.
  • By using a partitioned view, the data still appears as a single table and can be queried as such without having to reference the correct underlying table manually.
    Partitioned views are updatable if either of these conditions is met:
  • An INSTEAD OF trigger is defined on the view with logic to support INSERT, UPDATE, and DELETE statements.Both the view and the INSERT, UPDATE, and DELETE statements follow the rules defined for updatable partitioned views.

Dis Advantages of views:
So, if you have a view joining 10 tables and one of those tables has a million rows, your view will return at least 1 million rows. Joining such a view to a few other tables within a stored procedure could be disastrous.
What should you do? A better alternative in such cases would be a user-defined function (UDF), which accepts parameters and allows you to limit the number of returned rows. Another option is to join all tables within a single unit stored procedure and limit the output by using parameters.

SQL Server Joins

Joins:
Joins in SQL Server allows the retrieval of data records from one or more tables having some relation between them. Logical operators can also be used to drill down the number of records to get the desired output from sql join queries.
Types:

  • Inner Join
  • Outer Join 1)Left Outer Join 2)Right Outer Join 3)Full Outer Join
  • Cross Join
  • Inner Join: Inner Join is a default type join of SQL Server. It uses logical operators such as =, <, > to match the records in two tables. Inner Join includes equi join and natural joins.
  • Example:
  • SELECT C.CATEGORYID, C.CATEGORYNAME, P.PRODUCTID, P.PRODUCTNAME, P.UNITPRICE FROM CATEGORIES C INNER JOINPRODUCTS P ON P.CATEGORYID = C.CATEGORYIDWHERE P.UNITPRICE = 10ORDER BY C.CATEGORYNAME, P.PRODUCTNAME
  • Outer Join:
  • Outer Join has further 3 sub categories as left, right and full. Outer Join uses these category names as keywords that can be specified in the FROM clause.
    Left Outer Join: Left Outer Join returns all the rows from the table specified first in the Left Outer Join Clause. If in the left table any row has no matching record in the right side table then that row returns null column values for that particular tuple.
  • Example:
    SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A LEFT OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME
    Cheryl
    Carson
    Algodata Infosystems
    Michel
    DeFrance
    NULL

    Right Outer Join:
  • Right Outer Join is exactly the reverse method of Left Outer Join. It returns all the rows from right table and returns null values for the rows having no match in the left joined table.
    Example:
  • SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A RIGHT OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME

    Full Outer Join: Full outer join returns all the rows from both left and right joined tables. If there is any match missing from the left table then it returns null column values for left side table and if there is any match missing from right table then it returns null value columns for the right side table.
    SELECT A.AU_FNAME, A.AU_LNAME, P.PUB_NAMEFROM AUTHORS A FULL OUTER JOIN PUBLISHERS PON A.CITY = P.CITYORDER BY A.AU_LNAME, A.AU_FNAME
  • Cross Join: Cross join works as a Cartesian product of rows for both left and right table. It combined each row of left table with all the rows of right table.
  • Example:
    SELECT AU_FNAME, AU_LNAME, PUB_NAMEFROM AUTHORS CROSS JOIN PUBLISHERS WHERE AUTHORS.CITY = PUBLISHERS.CITYORDER BY AU_FNAME

Wednesday, January 7, 2009

SQL Server Interview Questions

What is DTS in SQL Server ?

Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.

What is the significance of NULL value and why should we avoid permitting null values?

Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.

Difference between primary key and Unique key?

  • Both constraints will share a common property called uniqueness. The data in the column should be unique.
  • The basic difference is,• Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.•
  • On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
  • Only one primary key can be created for the table. Any number of Unique key can be created for the table.

What is normalization?

Normalization is the basic concept used in designing a database. Its nothing but, an advise given to the database to have minimal repetition of data, highly structured, highly secured, easy to retrieve. In high level definition, the Process of organizing data into tables is referred to as normalization. Denormalization:As the name indicates, it's opposite to normalisation. Introducing redundancy into the database is referred to as denormalization. The database becomes too complex and too many joins may occur to fetch the data. In that case, we used to prefer this denomalization concept. Narrow idea - Joining the divided or segregated tables.What is the difference between UNION ALL Statement and UNION ?The main difference between UNION ALL statement and UNION is UNION All statement is much faster than UNION,the reason behind this is that because UNION ALL statement does not look for duplicate rows, but on the other hand UNION statement does look for duplicate rows, whether or not they exist

What is a view?

If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.
What are the types of indexes available with SQL Server?

There are basically two types of indexes that we use with the SQL ServerClustered -

1. It will format the entire table, inturn physically sort the table.

2. Only one clustered index can be created for a table.

3. Data will be located in the leaf level.

4. By default, primary key will create clustered index on the table

.Non-Clustered Index

1. It wont touch the structure of the table.

2. It forms an index table as reference to the exact data.

3. A reference to the data will be located in the leaf level.

4. For a table, we can create 249 non clustered index

Stored Procedure Vs User Defined functions

in sql server Stored Procedure:Its a pre-compiled statements incorporating a set of T-SQL statements.We can't use SP in Joins.Stored procedure won't return table variables.User defined functions:Its a set of T-SQL statements. Repeated T-SQL statements can be grouped as a User defined functions.We can use UDF's and in joins.UDF returns table variablesCorrelated maximum capacity for SQL Server 2005:

Table Level:

  • Maximum Number of tables : No restrictions (Until your harddisk size you can create tables)
  • Maximum bytes per row in the table : 8060 bytes
  • Maximum tables in a select statment - 256
  • Maxiumu references per table - 253
  • Maximum rows in the table - Unlimited (Depends on the storage)
  • Maximum columns per base table : 1024
  • Maximum columns per insert statment : 1024
  • Maximum columns per Select statment : 1024 * 4 = 4096Bytes per Group by or Order by = 8000
    Index:
  • Maximum clustered index per table - 1
  • Maximum Non-clustered index per table - 249Maximum Columns in an index (composite index) - 16
    Keys:
  • Maximum Columns in a Primary key - 16
  • Maximum Columns in a Foreign key - 16
    Objects:
  • Nested Stored procedure levels- 32
  • Nested triggers levels- 32
  • Parameters per stored procedure - 2100
  • Parameters per User defined functions - 2100
  • Identifier length - 16
    Database Level Details:
  • Number of instances for a server - 50
  • Files per database - 32767
  • Filegroups per database - 32767
  • Databases per instance of SQL Server – 32767


Delete VS Truncate:

  • Delete will delete row by row in the table. The syntax is,delete from tablenameWe can give where conditions for deleting the data. Each delete will be logged in the log file.Its a DML statement
  • Trucate will deallocate the reference in the pages instead of deleting the data.Its DDL statement.
  • The syntax is,Truncate table tablenameWe can provide truncate with tables having foreign key relationships. (Because it wont do any cascade delete on the table).It wont log any information in the log file.Delete or truncate the data at a stretch and wont do any row by row manipulation