Home Blog Page 10

Creating a Site Collection Template from A Web Template in SharePoint 2010

First off, I should state that there’s really no such thing as a site collection template. What happens when a new site collection is created is that the collection gets created, and then a web template is applied to the root site. This whole process is actually decoupled in SharePoint 2010, and you no longer need to select a template when the site collection is created (as documented previously by Todd Klindt). Todd has a very clever solution to getting your web template to be used at the root site, but I recently had a requirement to have it fully automated, and to be visible to the templates available when creating a site collection in Central admin.

This was relatively straightforward in SharePoint 2007, you would save a particular site as a template, then go to the template gallery, download it to the file system on a front end server, and then run an STSADM command to have it added to the Site definitions list. However, in SharePoint 2010, site templates are no longer .STP files,they use .WSP solutions in the user solution gallery. That should be easy,right? Just save off the WSP file, add the solution to the farm with either PowerShell or STSADM. The solution will actually install, but your site template won’t show up. The main reason is that the actual web template is scoped to “web” and for it to show up for site collections, it needs to be scoped for the farm.

The good news is that you can import a WSP file directly into Visual Studio 2010, edit it, and create a new solution that does work. I will now attempt to describe the relevant steps, and a few gotchas to do this.

1. Save The Site as a Template

Once you have your site looking and behaving the way that you want, it’s time to save it off. Select Site Settings, and click Save Site As Template – It’s under the Site Actions section. Give the template a file name, name, and if desired, a description. Once you select OK, the solution will be created and saved to the solution gallery, which is at the root of the site collection. You’ll want to go there next, and you can do so by clicking on the “solution gallery” link in the successful save confirmation page, or by navigating to the root of the site collection, then selecting Site Actions – Site Settings and clicking on the Solutions Gallery link. There is no more Site Template Gallery!!!

2. Save the WSP File Locally

From the solutions gallery, Click the name of your solution, and you will be prompted to save the wsp file. Go ahead and do that, and then you need to delete the template from the gallery. Why? You’ll be ultimately registering it in the farm, and you don’t need any confusion as to which template to choose. As well, if you’ll be using the same name, this will lead to conflicts, so it’s best to eliminate it altogether.

3. Create a Project in Visual Studio

Open Visual Studio and create a new project. Make sure that you have the SharePoint 2010 Templates showing, and then select the “Import SharePoint Solution Package” template.

From the next screen select “Deploy As a Farm Solution”, and click Next.

Next, click Browse and navigate to the WSP file downloaded in 2.

Finally, ensure that all of the included items are selected, and select Finish.

Visual Studio will then import all of the items into the project. Now we’re ready to modify the project.

4. Modify The Feature Definitions

There will typically be 4 Features created for a site template, aptly named Feature1 through Feature 4. Personally, I like my feature names to be a little more descriptive than that. Feature 1 is for List Instances, Feature 2 is for Modules, Feature 3 is for the template itself, and Feature 4 is for the PropertyBag.

The purpose of our solution is to make the site template available, and the other features are effectively there in a supporting role. Currently, all 4 features are scoped to web, and all 4 are visible. In addition to renaming them, we want to hide features 1,2, and 4 from display, and we want to scope feature 3 to the farm.

First, we’ll modify the Feature name. Simply Single Click (or right click and rename) on the Feature in the Visual Studio Solution Explorer, and enter a new name. You’ll notice that all of the supporting elements below are automatically renamed as well.

Next, We’ll want to modify the Title of the features. The title is what is used when the feature is displayed in the feature list. Although we’ll be hiding 3 of them, it’s still a good idea to use a descriptive title. Double click on the feature, and the Feature Definition box will open in the main window. Modify the Title, and if desired the Description field to something meaningful to your users.

Go ahead and repeat this step for all of the 4 features

With the feature definition in the main window, the feature properties should be loaded in the properties toolbox (if you don’t have it open, open it). We want to set the Is Hidden property to true for all of the features except for the Web Template feature itself (Feature 3).

The web template feature itself requires an additional modification, we need to change the scope from site to farm. We can do this in either the properties window or the feature definition window, but the feature definition window is a little more obvious.

5. Modify the Template Definition Itself.

This step may not be required if the template name and title will be identical to that which was saved initially. However, in this case, we have called the solution Sample 1, and when the template was saved, it was MyCustomSite. We need to modify the template itself to be called Sample 1, and we may have some additional tweaks.

From the Solution Explorer, open the Web Templates Folder and change the name of the Template by single, or right clicking on it. The feature definitions will be updated automatically.

Next, we need to open the Elements.xml file, and change the Name and the Title tag to the new name. Search and replace is a good idea here. Next, open the ONet.xml and change the Title attribute in the Project tag to an appropriate value, in this case, Sample 1. This file can also be used to remove any feature dependencies that may not exist in the destination farm, but be careful – other elements of your template may be reliant on them.

6. Test the Project

Click on the Debug start button in Visual Studio and your template will be deployed to the server, and you’ll be prompted to create a new subsite. If you see your template in the custom tab, all is well. Go ahead and create a test site to make sure that everything is working. Visual studio may prompt you with deployment conflicts, just let it go ahead and resolve them automatically.

7. Deploy the Solution

We are now ready to deploy the solution to the farm. First, set Visual Studio to Release mode from the toolbar:

Then, Right Click on the project, and select Package

Then, you’ll need to navigate to your Visual Studio project folder, and then into the BINRelease folder. There you will find a .WSP file with the name of your project. You can either work with the file in place, or copy it to a folder, but next we will add the project to the Farm solution gallery. To do this, we will either use STSADM (old school) or PowerShell (the cool new way). I’m old, so I still use STSADM for solutions, but I’ll show both.

To add the solution using stsadm.exe, open up a command prompt (in administrator mode if UAC is turned on), and navigate to the folder containing the solution file. The syntax is:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BINstsadm.exe –o addsolution –filename sample1.wsp

Where sample1.wsp is the name of your solution file.

To use PowerShell, open the SharePoint 2010 Management Shell, and enter:

add-SPsolution –LiteralPath c:solutionssample1.wsp

The argument for LiteralPath is the complete path to the solution file. If there are and spaces in the path name, it needs to be encased in quotes.

8. Deploy the Solution

Now that the solution has been added, it needs to be deployed. To do so, start central admin, Go to System Settings, and select Manage farm solutions in the Farm Management Section:

Click on your solution name, and then click the Deploy Solution button. Click the OK button on the following screen, and your solution will be deployed.

You can control whether or not the template is available by turning off the farm feature. You can do that from central admin by navigating to System Settings – Manage Farm Features. From here, you can turn your template on and off.

9. Create New Site Collection

At this point, we should be good to go. From Central Administration, navigate to Application Management, and click Create Site Collections. On the create screen, give the new collection a title, and a URL. Then, in the Template Selection, click the Custom tab, and your template should appear there.


Give it a site collection administrator, and click OK. After a few moments, the site will be created, and you can navigate to it.

For more details please refer to following useful links

http://blogs.msdn.com/b/vesku/archive/2010/10/14/sharepoint-2010-and-web-templates.aspx#sitetemplate

http://praveenbattula.blogspot.com/2010/02/sharepoint-2010-site-templates-not.html

http://whitepages.unlimitedviz.com/2010/10/how-to-build-a-site-collection-template-from-a-web-template-in-sharepoint-2010/

http://office.microsoft.com/en-us/sharepoint-designer-help/save-a-sharepoint-site-as-a-template-HA101782501.aspx#_Toc258332698

 

Some Concepts and Interview Questions for PHP/MySQL platform

4

Some Concepts and Interview Questions for PHP/MySQL platform

IN HOW MANY WAYS WE CAN RETRIEVE DATA IN THE RESULT SET OF MYSQL USING PHP?

mysql_fetch_array – Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc – Fetch a result row as an associative array
mysql_fetch_object – Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array

 

How can we get second of the current time using date function?

$second = date(“s”);

 

 

How can we encrypt and decrypt a data presented in a table using MySQL?

You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:

AES_ENCRYPT(str, key_str)
AES_DECRYPT(crypt_str, key_str)

 

 

If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?

100, it’s a reference to existing variable.

 

 

 

 

Some MCQ’s for PHP Development

 

1)      Which of the following DBMSs do not have a native PHP extension?

 

A) MySQL

B) IBM DB/2

C) PostgreSQL

D) Microsoft SQL Server

E) None of the above

 

2)In PHP in order to access MySQL database you will use:

 

A) mysqlconnect() function

B) mysql-connect() function

C) mysql_connect() function

D) sql_connect() function

 

3)Transactions are used to treat sets of SQL statements atomically.

 

A) True

B) False

 

4)SQL is not case sensitive. SELECT is the same as select.

 

A) True

B) False

 

5)Which of the following is not an SQL aggregate function?

A) AVG

B) SUM

C) MIN

D) MAX

E) CURRENT_DATE()

 

6)What does the DESC keyword do in the following query?

SELECT *

FROM MY_TABLE

WHERE ID > 0

ORDER BY ID, NAME DESC

A) It causes the dataset returned by the query to be sorted in descending order

B) It causes rows with the same ID to be sorted by NAME in ascending order

C) It causes rows with the same ID to be sorted by NAME in descending order

D) It causes rows to be sorted by NAME first and then by ID

E) It causes the result set to include a description of the NAME field

 

7)The …………. statement is used to delete a table.

A) DROP TABLE

B) DELETE TABLE

C) DEL TABLE

D) REMOVE TABLE

 

 

8)What will happen at the end of the following sequence of SQL commands?

 

BEGIN TRANSACTION

DELETE FROM MYTABLE WHERE ID=1

DELETE FROM OTHERTABLE

ROLLBACK TRANSACTION

 

A) The contents of OTHERTABLE will be deleted

B) The contents of both OTHERTABLE and MYTABLE will be deleted

C) The contents of OTHERTABLE will be deleted, as will be all the contents of

MYTABLE whose ID is 1

D) The database will remain unchanged to all users except the one that executes

these queries.

E) The database will remain unchanged

 

9)Use the ………….. to delete the data inside the table, and not the table

itself?

A) DROP TABLE

B) DELETE TABLE

C) TRUNCATE TABLE

D) REMOVE TABLE

10)Can joins be nested?

A) True

B) False

 

 

Answers to MCQ’s

1) E, 2) C, 3) A, 4) A, 5) E, 6) C, 7) A, 8) E, 9) C, 10) A

 

Q:1 What are the differences between Get and post methods in form submitting.
give the case where we can use get and we can use post methods?
A:1

When to use GET or POST

The HTML 2.0 specification says, in section Form
Submission (and the HTML 4.0 specification repeats this with minor
stylistic changes):

–>If the processing of a form is idempotent
(i.e. it has no lasting observable effect on the state of the
world), then the form method should be GET. Many database searches
have no visible side-effects and make ideal applications of query
forms.

–>If the service associated with the processing of a form has side
effects (for example, modification of a database or subscription to
a service), the method should be POST.

How the form data is transmitted?

quotation from the HTML 4.0 specification

–> If the method is “get” – -, the user agent
takes the value of action, appends a ? to it, then appends the form
data set, encoded using the application/x-www-form-urlencoded
content type. The user agent then traverses the link to this URI. In
this scenario, form data are restricted to ASCII codes.
–> If the method is “post” –, the user agent conducts an HTTP post
transaction using the value of the action attribute and a message
created according to the content type specified by the enctype
attribute.

Quote from CGI FAQ

Firstly, the the HTTP protocol specifies
differing usages for the two methods. GET requests should always be
idempotent on the server. This means that whereas one GET request
might (rarely) change some state on the Server, two or more
identical requests will have no further effect.

This is a theoretical point which is also good
advice in practice. If a user hits “reload” on his/her browser, an
identical request will be sent to the server, potentially resulting
in two identical database or
guestbook entries, counter increments, etc. Browsers may reload a
GET URL automatically, particularly if cacheing is disabled (as is
usually the case with CGI output), but will typically prompt the
user before
re-submitting a POST request. This means you’re far less likely to
get inadvertently-repeated entries from POST.

GET is (in theory) the preferred method for
idempotent operations, such as querying a database, though it
matters little if you’re using a form. There is a further practical
constraint that many systems have built-in limits to the length of a
GET request they can handle: when the total size of a request (URL+params)
approaches or exceeds 1Kb, you are well-advised to use POST in any
case.

I would prefer POST when I don’t want the status to
be change when user resubmits. And GET
when it does not matter.

Q:2 Who is the father of PHP and explain the changes in PHP versions?
A:2 Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3
is the successor to PHP/FI 2.0 and is a lot nicer. PHP 4 is the current
generation of PHP, which uses the
Zend engine
under the
hood. PHP 5 uses
Zend engine 2 which,
among other things, offers many additionalOOP features
Q:3 How can we submit a form without a submit button?
A:3 The main idea behind this is to use Java script submit() function in
order to submit the form without explicitly clicking any submit button.
You can attach the document.formname.submit() method to onclick,
onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the
form after xx seconds once the loading is done (can be seen in online
test sites).
Q:4 In how many ways we can retrieve the data in the result set of
MySQL using PHP?
A:4 You can do it by 4 Ways1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc
Q:5 What is the difference between mysql_fetch_object and
mysql_fetch_array?
A:5 mysql_fetch_object() is similar tomysql_fetch_array(), with one difference –
an object is returned, instead of an array. Indirectly, that means that
you can only access the data by the field names, and not by their
offsets (numbers are illegal property names).
Q:6 What is the difference between $message and $$message?
A:6 It is a classic example of PHP’s variable variables. take the
following example.$message = “Mizan”;$$message = “is a moderator of PHPXperts.”;$message is a simple PHP variable that we are used to. But the
$$message is not a very familiar face. It creates a variable name $mizan
with the value “is a moderator of PHPXperts.” assigned. break it like
this${$message} => $mizanSometimes it is convenient to be able to have variable variable
names. That is, a variable name which can be set and used dynamically.
Q:7 How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’
using regular expression of PHP?
A:7 preg_match(“/^http:\/\/.+@(.+)$/”,’http://info@abc.com’,$found);
echo $found[1];
Q:8 How can we create a database using PHP and MySQL?
A:8 We can create MySQL database with the use of
mysql_create_db(“Database Name”)
Q:9 What are the differences between require and include,
include_once and require_once?
A:9 The include() statement includes
and evaluates the specified file.The documentation below also applies to
require(). The two constructs
are identical in every way except how they handle
failure. include() produces a
Warning while require() results
in a Fatal Error. In other words, use
require() if you want a missing
file to halt processing of the page.
include()
does not behave this way, the script will
continue regardless.The include_once()
statement includes and evaluates the
specified file during the execution of
the script. This is a behavior similar
to the include()
statement, with the only difference
being that if the code from a file has
already been included, it will not be
included again. As the name suggests, it
will be included just once.include_once()
should be used in cases where the same
file might be included and evaluated
more than once during a particular
execution of a script, and you want to
be sure that it is included exactly once
to avoid problems with function
redefinitions, variable value
reassignments, etc.

require_once()
should be used in cases where the same
file might be included and evaluated
more than once during a particular
execution of a script, and you want to
be sure that it is included exactly once
to avoid problems with function
redefinitions, variable value
reassignments, etc.

Q:10 Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
A:10 Yes we can use include() more than one time in any page though it is
not a very good practice.
Q:11 What are the different tables present in MySQL, which type of
table is generated when we are creating a table in the following syntax:
create table employee (eno int(2),ename varchar(10)) ?
A:11 Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
MyISAM is the default storage engine as of MySQL 3.23 and as a result if
we do not specify the table name explicitly it will be assigned to the
default engine.
Q:12 Functions in IMAP, POP3 AND LDAP?
A:12 You can find these specific information in PHP Manual.
Q:13 How can I execute a PHP script using command line?
A:13 As of version 4.3.0, PHP supports a new SAPI type (Server
Application Programming Interface) named CLI which means Command Line
Interface. Just run the PHP CLI (Command Line Interface) program and
provide the PHP script file name as the command line argument. For
example, “php myScript.php”, assuming “php” is the command to invoke the
CLI program.
Be aware that if your PHP script was written for the Web CGI interface,
it may not execute properly in command line environment.
Q:14 Suppose your Zend engine supports the mode <? ?> Then how can u
configure your PHP Zend engine to support <?PHP ?> mode ?
A:14 In php.ini file:
set
short_open_tag=on
to make PHP support
Q:15 Shopping cart online validation i.e. how can we configure Paypal,
etc.?
A:15 We can find the detail documentation about different paypal
integration process at the following site

PayPal PHP
SDK : http://www.paypaldev.org

Q:16 What is meant by nl2br()?
A:16 Inserts HTML line breaks (<BR />) before all newlines in a string
string nl2br (string); Returns string with ” inserted before all
newlines. For example: echo nl2br(“god bless\n you”) will output “god
bless <br /> you” to your browser.
Q:17 Draw the architecture of Zend engine?
A:17 The Zend Engine is the internal compiler and runtime engine used by
PHP4. Developed by Zeev Suraski and Andi Gutmans, the Zend Engine is an
abbreviation of their names. In the early days of PHP4, it worked as
follows:
The PHP script was loaded by the Zend Engine and compiled into Zend
opcode. Opcodes, short for operation codes, are low level binary
instructions. Then the opcode was executed and the HTML generated sent
to the client. The opcode was flushed from memory after execution.Today, there are a multitude of products and techniques to help you
speed up this process. In the following diagram, we show the how modern
PHP scripts work; all the shaded boxes are optional.
PHP Scripts are loaded into memory and compiled into Zend opcodes.
Q:18 What are the current versions of apache, PHP, and MySQL?
A:18 As of February, 2007 the current versions arePHP: php5.2.1
MySQL: MySQL 5.2
Apache: Apache 2.2.4Note: visit www.php.net,http://dev.mysql.com/downloads/mysql/

,

www.apache.org to get current
versions.

Q:19 What are the reasons for selecting lamp (Linux, apache, MySQL,
PHP) instead of combination of other software programs, servers and
operating systems?
A:19 All of those are open source resource. Security of Linux is very
very more than windows. Apache is a better server that IIS both in
functionality and security. MySQL is world most popular open source
database. PHP is more faster that asp or any other scripting language.
Q:20 How can we encrypt and decrypt a data present in a MySQL table
using MySQL?
A:20 AES_ENCRYPT () and AES_DECRYPT ()
Q:21 How can we encrypt the username and password using PHP?
A:21 The functions in this section perform encryption and decryption, and
compression and uncompression:

encryption decryption
AES_ENCRYT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() Not available
MD5() Not available
OLD_PASSWORD() Not available
PASSWORD() Not available
SHA() or SHA1() Not available
Not available UNCOMPRESSED_LENGTH()
Q:22 What are the features and advantages of object-oriented
programming?
A:22 One of the main advantages of OO programming is its ease of
modification; objects can easily be modified and added to a system there
by reducing maintenance costs. OO programming is also considered to be
better at modeling the real world than is procedural programming. It
allows for more complicated and flexible interactions. OO systems are
also easier for non-technical personnel to understand and easier for
them to participate in the maintenance and enhancement of a system
because it appeals to natural human cognition patterns.
For some systems, an OO approach can speed development time since many
objects are standard across systems and can be reused. Components that
manage dates, shipping, shopping carts, etc. can be purchased and easily
modified for a specific system
Q:23 What are the differences between procedure-oriented languages and
object-oriented languages?
A:23 Traditional programming has the following characteristics:Functions are written sequentially, so that a change in programming can
affect any code that follows it.
If a function is used multiple times in a system (i.e., a piece of code
that manages the date), it is often simply cut and pasted into each
program (i.e., a change log, order function, fulfillment system, etc).
If a date change is needed (i.e., Y2K when the code needed to be changed
to handle four numerical digits instead of two), all these pieces of
code must be found, modified, and tested.
Code (sequences of computer instructions) and data (information on which
the instructions operates on) are kept separate. Multiple sets of code
can access and modify one set of data. One set of code may rely on data
in multiple places. Multiple sets of code and data are required to work
together. Changes made to any of the code sets and data sets can cause
problems through out the system.Object-Oriented programming takes a radically different approach:Code and data are merged into one indivisible item – an object (the
term “component” has also been used to describe an object.) An object is
an abstraction of a set of real-world things (for example, an object may
be created around “date”) The object would contain all information and
functionality for that thing (A date
object it may contain labels like January, February, Tuesday, Wednesday.
It may contain functionality that manages leap years, determines if it
is a business day or a holiday, etc., See Fig. 1). Ideally, information
about a particular thing should reside in only one place in a system.
The information within an object is encapsulated (or hidden) from the
rest of the system.
A system is composed of multiple objects (i.e., date function, reports,
order processing, etc., See Fig 2). When one object needs information
from another object, a request is sent asking for specific information.
(for example, a report object may need to know what today’s date is and
will send a request to the date object) These requests are called
messages and each object has an interface that manages messages.
OO programming languages include features such as “class”, “instance”,
“inheritance”, and “polymorphism” that increase the power and
flexibility of an object.
Q:24 What is the use of friend function?
A:24 Sometimes a function is best shared among a number of different
classes. Such functions can be declared either as member functions of
one class or as global functions. In either case they can be set to be
friends of other classes, by using a friend specifier in the class that
is admitting them. Such functions can use all attributes of the class
which names them as a friend, as if they were themselves members of that
class.
A friend declaration is essentially a prototype for a member function,
but instead of requiring an implementation with the name of that class
attached by the double colon syntax, a global function or member
function of another class provides the match.
Q:25 What are the differences between public, private, protected,
static, transient, final and volatile?
A:25 Public: Public declared items can be accessed everywhere.
Protected: Protected limits access to inherited and parent
classes (and to the class that defines the item).
Private: Private limits visibility only to the class that defines
the item.
Static: A static variable exists only in a local function scope,
but it does not lose its value when program execution leaves this scope.
Final: Final keyword prevents child classes from overriding a
method by prefixing the definition with final. If the class itself is
being defined final then it cannot be extended.
transient: A transient variable is a variable that may not
be serialized.
volatile:
a variable that might be concurrently modified by multiple
threads should be declared volatile. Variables declared to be volatile
will not be optimized by the compiler because their value can change at
any time.
Q:26 What are the different types of errors in PHP?
A:26 Three are three types of errors:1. Notices: These are trivial,
non-critical errors that PHP encounters while executing a script – for
example, accessing a variable that has not yet been defined. By default,
such errors are not displayed to the user at all – although, as you will
see, you can change this default behavior.2. Warnings: These are more serious errors – for example, attempting
to include() a file which does not exist. By default, these errors are
displayed to the user, but they do not result in script termination.3. Fatal errors: These are critical errors – for example,
instantiating an object of a non-existent class, or calling a
non-existent function. These errors cause the immediate termination of
the script, and PHP’s default behavior is to display them to the user
when they take place.
Q:27 What is the functionality of the function strstr and stristr?
A:27 strstr:Returns part of haystack
string from the first occurrence of
needle to the end of
haystack.If needle is not found,
returns FALSE.

If needle is not a
string, it is converted to an integer and applied as the
ordinal value of a character.

This function is case-sensitive. For
case-insensitive searches, use
stristr().

Q:28 What are the differences between PHP 3 and PHP 4 and PHP 5?
A:28 Please read the release notes at
http://www.php.net.
Q:29 How can we convert asp pages to PHP pages?
A:29 there are lots of tools available for asp to PHP conversion. you can
search Google for that. the best one is available athttp://asp2php.naken.cc./
Q:30 What is the functionality of the function htmlentities?
A:30 Convert all applicable characters to HTML entities
This function is identical to htmlspecialchars() in all ways, except
with htmlentities(), all characters which have HTML character entity
equivalents are translated into these entities.
Q:31 How can we get second of the current time using date function?
A:31 $second = date(“s”);
Q:32 How can we convert the time zones using PHP?
A:32 By using date_default_timezone_get and
date_default_timezone_set function on PHP 5.1.0

<?php
// Discover what 8am in Tokyo relates to on the East Coast of the US    

// Set the default timezone to Tokyo time:
date_default_timezone_set('Asia/Tokyo');    

// Now generate the timestamp for that particular timezone, on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);    

// Now set the timezone back to US/Eastern
date_default_timezone_set('US/Eastern');    

// Output the date in a standard format (RFC1123), this will print:
// Fri, 31 Dec 1999 18:00:00 EST
echo '<p>', date(DATE_RFC1123, $stamp) ,'</p>';?>
Q:33 What is meant by urlencode and urldocode?
A:33 URLencode returns a string in which all non-alphanumeric characters
except -_. have been replaced with a percent (%)
sign followed by two hex digits and spaces encoded as plus (+)
signs. It is encoded the same way that the posted data from a WWW form
is encoded, that is the same way as in
application/x-www-form-urlencodedmedia type.urldecode decodes any %##
encoding in the given string.
Q:34 What is the difference between the functions unlink and unset?
A:34 unlink() deletes the given file from the file system.
unset() makes a variable undefined.
Q:35 How can we register the variables into a session?
A:35 $_SESSION[’name’] = “Mizan”;
Q:36 How can we get the properties (size, type, width, height) of an
image using PHP image functions?
A:36 To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function t
Q:37 How can we get the browser properties using PHP?
A:37 By using
$_SERVER['HTTP_USER_AGENT']
variable.
Q:38 What is the maximum size of a file that can be uploaded using PHP
and how can we change this?
A:38 By default the maximum size is 2MB. and we can change the following
setup at php.iniupload_max_filesize = 2M
Q:39 How can we increase the execution time of a PHP script?
A:39 by changing the following setup at php.inimax_execution_time = 30
; Maximum execution time of each script, in seconds
Q:40 How can we take a backup of a MySQL table and how can we restore
it. ?
A:40 To backup: BACKUP TABLE tbl_name[,tbl_name…] TO
‘/path/to/backup/directory’
RESTORE TABLE tbl_name[,tbl_name…] FROM ‘/path/to/backup/directory’mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or
for transferring the data to another SQL server (not necessarily a MySQL
server). The dump will contain SQL statements to create the table and/or
populate the table.
-t, –no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, –no-data
Don’t write any row information for the table. This is very useful if
you just want to get a dump of the structure for a table!
Q:41 How can we optimize or increase the speed of a MySQL select
query?
A:41
  • first of all instead of using select * from table1, use select
    column1, column2, column3.. from table1
  • Look for the opportunity to introduce index in the table you are
    querying.
  • use limit keyword if you are looking for any specific number of
    rows from the result set.
Q:42 How many ways can we get the value of current session id?
A:42 session_id() returns the session id for the current session.
Q:43 How can we destroy the session, how can we unset the variable of
a session?
A:43 session_unregister — Unregister a global variable from the current
session
session_unset — Free all session variables
Q:44 How can we destroy the cookie?
A:44 Set the cookie in past.
Q:45 How many ways we can pass the variable through the navigation
between the pages?
A:45
  • GET/QueryString
  • POST
Q:46 What is the difference between ereg_replace() and eregi_replace()?
A:46 eregi_replace() function is identical to ereg_replace() except that
this ignores case distinction when matching alphabetic
characters.eregi_replace() function is identical to ereg_replace()
except that this ignores case distinction when matching alphabetic
characters.
Q:47 What are the different functions in sorting an array?
A:47 Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and
uksort().
Q:48 How can we know the count/number of elements of an array?
A:48 2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)
Q:49 What is the PHP predefined variable that tells the What types of
images that PHP supports?
A:49 Though i am not sure if this is wrong or not, With the exif
extension you are able to work with image meta data.
Q:50 How can I know that a variable is a number or not using a
JavaScript?
A:50 bool is_numeric ( mixed var)
Returns TRUE if var is a number or a numeric string, FALSE otherwise.or use isNaN(mixed var)The isNaN() function is used to check if a value is not a number.
Q:51 List out some tools through which we can draw E-R diagrams for
mysql.
A:51 Case Studio
Smart Draw
Q:52 How can I retrieve values from one database server and store them
in other database server using PHP?
A:52 we can always fetch from one database and rewrite to another. here
is a nice solution of it.$db1 = mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db1″, $db1);
$res1 = mysql_query(“query”,$db1);$db2 = mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db2″, $db2);
$res2 = mysql_query(“query”,$db2);At this point you can only fetch records from you previous ResultSet,
i.e $res1 – But you cannot execute new query in $db1, even if you
supply the link as because the link was overwritten by the new db.so at this point the following script will fail
$res3 = mysql_query(“query”,$db1); //this will failSo how to solve that?take a look below.
$db1 = mysql_connect(“host”,”user”,”pwd”)
mysql_select_db(“db1″, $db1);
$res1 = mysql_query(“query”,$db1);

$db2 = mysql_connect(“host”,”user”,”pwd”, true)
mysql_select_db(“db2″, $db2);
$res2 = mysql_query(“query”,$db2);

So mysql_connect has another optional boolean parameter which
indicates whether a link will be created or not. as we connect to the
$db2 with this optional parameter set to ‘true’, so both link will
remain live.

now the following query will execute successfully.
$res3 = mysql_query(“query”,$db1);

Thanks goes to Hasan and Hasin for this solution.

Q:53 List out the predefined classes in PHP?
A:53 Directory
stdClass
__PHP_Incomplete_Class
exception
php_user_filter
Q:54 How can I make a script that can be bi-language (supports
English, German)?
A:54 You can maintain two separate language file for each of the
language. all the labels are putted in both language files as variables
and assign those variables in the PHP source. on runtime choose the
required language option.
Q:55 What are the difference between abstract class and interface?
A:55 Abstract class: abstract classes are the class where one or more
methods are abstract but not necessarily all method has to be abstract.
Abstract methods are the methods, which are declare in its class but not
define. The definition of those methods must be in its extending class.Interface: Interfaces are one type of class where all the methods are
abstract. That means all the methods only declared but not defined. All
the methods must be define by its implemented class.
Q:56 How can we send mail using JavaScript?
A:56 JavaScript does not have any networking capabilities as it is
designed to work on client site. As a result we can not send mails using
JavaScript. But we can call the client side mail protocol mailto
via JavaScript to prompt for an email to send. this requires the client
to approve it.
Q:57 How can we repair a MySQL table?
A:57 The syntex for repairing a MySQL table is
REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
This command will repair the table specified if the quick is given the
MySQL will do a repair of only the index tree if the extended is given
it will create index row by row
Q:58 What are the advantages of stored procedures, triggers, indexes?
A:58 A stored procedure is a set of SQL commands that can be compiled and
stored in the server. Once this has been done, clients don’t need to
keep re-issuing the entire query but can refer to the stored procedure.
This provides better overall performance because the query has to be
parsed only once, and less information needs to be sent between the
server and the client. You can also raise the conceptual level by having
libraries of functions in the server. However, stored procedures of
course do increase the load on the database server system, as more of
the work is done on the server side and less on the client (application)
side.Triggers will also be implemented. A trigger is effectively a type of
stored procedure, one that is invoked when a particular event occurs.
For example, you can install a stored procedure that is triggered each
time a record is deleted from a transaction table and that stored
procedure automatically deletes the corresponding customer from a
customer table when all his transactions are deleted.Indexes are used to find rows with specific column values quickly.
Without an index, MySQL must begin with the first row and then read
through the entire table to find the relevant rows. The larger the
table, the more this costs. If the table has an index for the columns in
question, MySQL can quickly determine the position to seek to in the
middle of the data file without having to look at all the data. If a
table has 1,000 rows, this is at least 100 times faster than reading
sequentially. If you need to access most of the rows, it is faster to
read sequentially, because this minimizes disk seeks.
Q:59 What is the maximum length of a table name, database name, and
fieldname in MySQL?
A:59 The following table describes the maximum length for each type of
identifier.

Identifier Maximum Length
(bytes)
Database 64
Table 64
Column 64
Index 64
Alias 255

There are some restrictions on the characters that may appear in
identifiers:

Q:60 How many values can the SET function of MySQL take?
A:60 MySQL set can take zero or more values but at the maximum it can
take 64 values
Q:61 What are the other commands to know the structure of table using
MySQL commands except explain command?
A:61 describe Table-Name;
Q:62 How many tables will create when we create table, what are they?
A:62 The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension,
Q:63 What is the purpose of the following files having extensions 1) .frm
2) .myd 3) .myi? What do these files contain?
A:63 In MySql, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names
that begin with the table name and have an extension to indicate the
file type.
The ‘.frm’ file stores the table definition.
The data file has a ‘.MYD’ (MYData) extension.
The index file has a ‘.MYI’ (MYIndex) extension,
Q:64 What is maximum size of a database in MySQL?
A:64 If the operating system or filesystem places a limit on the number
of files in a directory, MySQL is bound by that constraint.The efficiency of the operating system in handling large numbers of
files in a directory can place a practical limit on the number of tables
in a database. If the time required to open a file in the directory
increases significantly as the number of files increases, database
performance can be adversely affected.
The amount of available disk space limits the number of tables.
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM
storage engine in MySQL 3.23, the maximum table size was increased to
65536 terabytes (2567 – 1 bytes). With this larger allowed table size,
the maximum effective table size for MySQL databases is usually
determined by operating system constraints on file sizes, not by MySQL
internal limits.The InnoDB storage engine maintains InnoDB tables within a tablespace
that can be created from several files. This allows a table to exceed
the maximum individual file size. The tablespace can include raw disk
partitions, which allows extremely large tables. The maximum tablespace
size is 64TB.
The following table lists some examples of operating system file-size
limits. This is only a rough guide and is not intended to be definitive.
For the most up-to-date information, be sure to check the documentation
specific to your operating system.
Operating System File-size LimitLinux 2.2-Intel 32-bit 2GB (LFS: 4GB)
Linux 2.4+ (using ext3 filesystem) 4TB
Solaris 9/10 16TB
NetWare w/NSS filesystem 8TB
Win32 w/ FAT/FAT32 2GB/4GB
Win32 w/ NTFS 2TB (possibly larger)
MacOS X w/ HFS+ 2TB
Q:65 Give the syntax of Grant and Revoke commands?
A:65 The generic syntax for grant is as following
> GRANT [rights] on [database/s] TO [username@hostname] IDENTIFIED BY
[password]
now rights can be
a) All privileges
b) combination of create, drop, select, insert, update and delete etc.We can grant rights on all databse by using *.* or some specific
database by database.* or a specific table by database.table_name
username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition
password is simply the password of userThe generic syntax for revoke is as following
> REVOKE [rights] on [database/s] FROM [username@hostname]
now rights can be as explained above
a) All privileges
b) combination of create, drop, select, insert, update and delete etc.
username@hotsname can be either username@localhost, username@hostname
and username@%
where hostname is any valid hostname and % represents any name, the *.*
any condition
Q:66 Explain Normalization concept?
A:66 The normalization process involves getting our data to conform to
three progressive normal forms, and a higher level of normalization
cannot be achieved until the previous levels have been achieved (there
are actually five normal forms, but the last two are mainly academic and
will not be discussed).First Normal FormThe First Normal Form (or 1NF) involves removal of redundant data
from horizontal rows. We want to ensure that there is no duplication of
data in a given row, and that every column stores the least amount of
information possible (making the field atomic).Second Normal FormWhere the First Normal Form deals with redundancy of data across a
horizontal row, Second Normal Form (or 2NF) deals with redundancy of
data in vertical columns. As stated earlier, the normal forms are
progressive, so to achieve Second Normal Form, your tables must already
be in First Normal Form.Third Normal FormI have a confession to make; I do not often use Third Normal Form. In
Third Normal Form we are looking for data in our tables that is not
fully dependant on the primary key, but dependant on another value in
the table
Q:67 How can we find the number of rows in a table using MySQL?
A:67 Use this for mysql
> SELECT COUNT(*) FROM table_name;
Q:68 How can we find the number of rows in a result set using PHP?
A:68 $result = mysql_query($sql, $db_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";
Q:69 How many ways we can we find the current date using MySQL?
A:69 SELECT CURDATE();
CURRENT_DATE() = CURDATE()
for time use
SELECT CURTIME();
CURRENT_TIME() = CURTIME()
Q:70 What are the advantages and disadvantages of Cascading Style
Sheets?
A:70 External Style SheetsAdvantagesCan control styles for multiple documents at once. Classes can be
created for use on multiple HTML element types in many documents.
Selector and grouping methods can be used to apply styles under complex
contextsDisadvantagesAn extra download is required to import style information for each
document The rendering of the document may be delayed until the external
style sheet is loaded Becomes slightly unwieldy for small quantities of
style definitionsEmbedded Style SheetsAdvantages

Classes can be created for use on multiple tag types in the document.
Selector and grouping methods can be used to apply styles under complex
contexts. No additional downloads necessary to receive style information

Disadvantages

This method can not control styles for multiple documents at once

Inline Styles

Advantages

Useful for small quantities of style definitions. Can override other
style specification methods at the local level so only exceptions need
to be listed in conjunction with other style methods

Disadvantages

Does not distance style information from content (a main goal of
SGML/HTML). Can not control styles for multiple documents at once.
Author can not create or control classes of elements to control multiple
element types within the document. Selector grouping methods can not be
used to create complex element addressing scenarios

Q:71 What type of inheritance that PHP supports?
A:71 In PHP an extended class is always dependent on a single base class,
that is, multiple inheritance is not supported. Classes are extended
using the keyword ‘extends’.
Q:72 What is the difference between Primary Key and
Unique key?
A:72 Primary Key: A column in a table whose values uniquely identify the
rows in the table. A primary key value cannot be NULL.Unique Key: Unique Keys are used to uniquely identify each row in the
table. There can be one and only one row for each unique key value. So
NULL can be a unique key.There can be only one primary key for a table but there can be more
than one unique for a table.

Q:73
The structure of table view buyers is as follows:

Field

Type

Null

Key

Default

Extra

user_pri_id int(15) PRI null auto_increment
userid varchar(10) YES null

the value of user_pri_id the last row 999 then What will happen in
the following conditions?

Condition1: Delete all the rows and insert another row then.
What is the starting value for this auto incremented field user_pri_id ,
Condition2: Delete the last row(having the field value 999) and
insert another row then. What is the value for this auto incremented
field user_pri_id

A:73 In both cases let the value for auto increment field be n then next
row will have value n+1 i.e. 1000
Q:74 What are the advantages/disadvantages of MySQL and PHP?
A:74 Both of them are open source software (so free of cost), support
cross platform. php is faster then ASP and JSP.
Q:75 What is the difference between GROUP BY and ORDER BY in Sql?
A:75 ORDER BY [col1],[col2],…,[coln]; Tels DBMS according to what columns
it should sort the result. If two rows will hawe the same value in col1
it will try to sort them according to col2 and so on.GROUP BY
[col1],[col2],…,[coln]; Tels DBMS to group results with same value of
column col1. You can use COUNT(col1), SUM(col1), AVG(col1) with it, if
you want to count all items in group, sum all values or view average
Q:76 What is the difference between char and varchar data types?
A:76 Set char to occupy n bytes and it will take n bytes even if u r
storing a value of n-m bytes
Set varchar to occupy n bytes and it will take only the required space
and will not use the n bytes
eg. name char(15) will waste 10 bytes if we store ‘mizan’, if each char
takes a byte
eg. name varchar(15) will just use 5 bytes if we store ‘mizan’, if each
char takes a byte. rest 10 bytes will be free.
Q:77 What is the functionality of md5 function in PHP?
A:77 Calculate the md5 hash of a string. The hash is a 32-character
hexadecimal number. I use it to generate keys which I use to identify
users etc. If I add random no techniques to it the md5 generated now
will be totally different for the same string I am using.
Q:78 How can I load data from a text file into a table?
A:78 you can use LOAD DATA INFILE file_name; syntax to load data
from a text file. but you have to make sure thata) data is delimited
b) columns and data matched correctly
Q:79 How can we know the number of days between two given dates using
MySQL?
A:79 SELECT DATEDIFF(’2007-03-07′,’2005-01-01′);
Q:80 How can we know the number of days between two given dates using
PHP?
A:80 $date1 = date(‘Y-m-d’);
$date2 = ’2006-08-15′;
$days = (strtotime($date1) – strtotime($date2)) / (60 * 60 * 24);

 

 

How to add multiple users (more than two users) as Site Collection Administrators?

3

We typically use the Central Administration Web site to create a site collection in a stand-alone deployment, while creating a new site collection it asks for only two Site collection Administrators (Primary and Secondary)

  1. Primary Site Collection Administrator to add the user name (in the form DOMAIN\username) for the user who will be the site collection administrator.
  2. Secondary Site Collection Administrator to add the user name for the secondary administrator of the site collection.

Anyhow, if we want to add (or remove) more than two users as Site Collection Administrators in Sharepoint 2010, following simple steps can be followed:

  1. On the Home page of the site collection, click Site Actions in the upper-right corner of the page, and then click Site Settings.
  2. In the Users and Permissions group/section, click the link Site collection administrators.
  3. In the Site Collection Administrators box, type the name of the user you want to add.

    If you are adding more than one user, separate the names or addresses with a semicolon.

  4. Click the Check Names icon to verify that you have entered the correct account name.

Thanks,
Web Editor

Microsoft SQL Server – Build versions

Please refer to this URL for detailed information about SQL Server builds:

http://sqlserverbuilds.blogspot.com/

 

Thanks,
Web Editor

 

TempDB Monitoring – Important SQL Queries

Here are few important TSQL queries to get the long running transactions and queries in TempDB for monitoring purposes.

  • Long-running transaction:

Sometimes transactions may run for long time preventing the shrinking of version store data.
The below queries will list the transactions that are running for long time.

SELECT top 10
	transaction_id as [Transacton ID],
	transaction_sequence_num as [Transation Sequence Number],
	elapsed_time_seconds as [Elapsed Time (in sec)]
FROM sys.dm_tran_active_snapshot_database_transactions
ORDER BY elapsed_time_seconds DESC

A long running transaction may prevent cleanup of transaction log thus eating up all log space available resulting space crisis for all other applications.

select
	transaction_id as [Transacton ID],
	[name]      as [Transaction Name],
	transaction_begin_time as [Transaction Begin Time],
	datediff(mi, transaction_begin_time, getdate()) as [Elapsed Time (in Min)],
	case transaction_type
		when 1 then 'Read/write'
      	when 2 then 'Read-only'
      	when 3 then 'System'
      	when 4 then 'Distributed'
	end as [Transaction Type],
	case transaction_state
		when 0 then 'The transaction has not been completely initialized yet.'
		when 1 then 'The transaction has been initialized but has not started.'
		when 2 then 'The transaction is active.'
		when 3 then 'The transaction has ended. This is used for read-only transactions.'
		when 4 then 'The commit process has been initiated on the distributed transaction. This is for distributed transactions only. The distributed transaction is still active but further processing cannot take place.'
		when 5 then 'The transaction is in a prepared state and waiting resolution.'
		when 6 then 'The transaction has been committed.'
		when 7 then 'The transaction is being rolled back.'
		when 8 then 'The transaction has been rolled back.'
	end as [Transaction Description]
from sys.dm_tran_active_transactions
  • Long running Queries:

sys.dm_exec_requests : Returns information regarding the requests made to the database server.

select
	host_name 			as [System Name],
	program_name 			as [Application Name],
	DB_NAME(database_id)    	as [Database Name],
	User_Name(user_id)            	as [User Name],
	connection_id 			as [Connection ID],
	sys.dm_exec_requests.session_id as [Current Session ID],
	blocking_session_id 		as [Blocking Session ID],
	start_time 			as [Request Start Time],
	sys.dm_exec_requests.status 	as [Status],
	command                         as [Command Type],
	(select text from sys.dm_exec_sql_text(sql_handle)) AS [Query Text],
	wait_type 			as [Waiting Type],
	wait_time 			as [Waiting Duration],
	wait_resource 			as [Waiting for Resource],
	sys.dm_exec_requests.transaction_id as [Transaction ID],
	percent_complete 		as [Percent Completed],
	estimated_completion_time 	as [Estimated Completion Time (in mili sec)],
	sys.dm_exec_requests.cpu_time 	as [CPU time used (in mili sec)],
	(memory_usage *  8   )            	as [Memory Usage (in KB)],
	sys.dm_exec_requests.total_elapsed_time as [Elapsed Time (in mili sec)]
from sys.dm_exec_requests
		inner join
	sys.dm_exec_sessions
		on sys.dm_exec_requests.session_id = sys.dm_exec_sessions.session_id
where DB_NAME(database_id) = 'tempdb'

Status: Status of the request.

This can be from one of the following options:
Background
Running
Runnable
Sleeping
Suspended

Command: Identifies the current type of command that is being processed.

Common command types include the following:
SELECT
INSERT
UPDATE
DELETE
BACKUP
LOG
BACKUP
DB DBCC
WAITFOR

Thanks,
Web Editor

SQL System Database – [TempDB] related internal information

This article covers SQL Server 2005/2008, and focuses on the most common ways to work with TEMPDB, not including every potential option.

 What Objects are Stored in TEMPDB?

TEMPDB is used to store three different categories of temporary data:

I.                        User Objects

II.                        Internal Objects

III.                        Version Stores

 

I.                   User Objects

Local and global temporary tables (and indexes if created)

User-defined tables and indexes

Table variables

II.                Internal Objects

  • Work tables for DBCC CHECKDB and DBCC CHECKTABLE.
  • Work tables for hash operations, such as joins andaggregations.
  • Work tables for processing static or keyset cursors.
  • Work tables for processing Service Broker objects.
  • Work files needed for many GROUP BY, ORDER BY, UNION,
  • SORT, and SELECT DISTINCT operations.
  • Work files for sorts that result from creating or rebuilding
  • indexes (SORT_IN_TEMPDB).
  • ·         The version store is a collection of pages used to store row level versioning of data.
  • There are two types of version stores:

III.             Version Stores

  1. I.         Common Version Store: Examples include:

–      Triggers.

–      Snapshot isolation and read-committed snapshot isolation.

–       MARS (when multiple active result sets are used).

  1. II.      Online-Index-Build Version Store:

–      Used for online index builds or rebuilds. EE edition only.

Some Important definitions related to TempDB

 

Snapshot Isolation: Specifies that data read by any statement in a transaction will be transactionally consistent with the data that existed at the start of the transaction. Data modifications made by other transactions after the start of the transaction are not visible to statements executing in the current transaction. The effect is as if the statements in a transaction gets a  snapshot of the committed data as it existed at the start of the transaction.

Read-Committed Snapshot Isolation: Row versioning is used to present each statement with a transactionally consistent snapshot of the data as it existed at the start of the statement. Locks are not used to protect the

data from updates by other transactions.

Multiple Active Results Sets (MARS): Allows applications to have more than one pending request per connection, and in particular, to have more than one active default result set per connection.

 

 

  

Some more Important concepts related to TemDb (That makes TempDb different in nature from other databases on SQL Server)

 

  • TEMPDB is cleared every time the SQL Server service is stopped and restarted.*
  • By default, TEMPDB creates an MDF file of 8MB and an LDF file of 1MB.
  • By default, autogrowth is set to grow by 10% with an unlimited MDF file size, and a 2TB maximum LDF file size.
  • Each SQL Server instance may have only one TEMPDB, although TEMPDB may have multiple physical files within a single filegroup.
  • Many TEMPDB database options can’t be changed (e.g. Database Read-Only, Auto Close, Auto Shrink).
  • TEMPDB only uses the simple recovery model.
  • TEMPDB may not be backed up, restored, be mirrored, have database snapshots made of it, or have many DBCCcommands run against it.

TEMPDB may not be dropped, detached, or attached.

  • TEMPDB logging works differently from regular logging.
  • Operations are minimally logged, as redo information is not included, which reduces TEMPDB transaction log activity. The log is truncated constantly during the automatic checkpoint process, and should not grow significantly, although it can grow with long-running transactions, or if disk I/O is bottlenecked.
  • If a TEMPDB log file grows wildly:
    • Check for long-running transactions (and kill them if necessary).
    • Check for I/O bottlenecks (and fix them if possible).
    • Manually running a checkpoint can often temporally reduce a wildly growing log file if bottle-necked disk I/O is the problem.

 

 TempDb Execution plans concepts

  • When a query execution plan is cached, user-created temporary objects in TEMPDB that are required by the plan are often cached as well. This is called temporary object reuse.
  • Obviously, not the entire object is cached, just a portion of it. When a temporary object is cached, up to nine pages are cached for reuse.
  • This improves the performance of the next execution of the query as the object already partially exists, but this also takes up space in TEMPDB.
  • If the system is low on memory, the Database Engine removes the execution plan and drops the cached temporary objects

 

Further more, The SQL Server system database, tempdb, has undergone a number of changes in SQL Server 2005. There are new tempdb usages and internal optimizations in SQL Server 2005; tempdb architecture is mostly unchanged since SQL Server 2000.

The tempdb system database is very similar to a user database. The main difference is that data in tempdb does not persist after SQL Server shuts down.

Each time SQL Server restarts, tempdb is copied from the model database. It inherits certain database configuration options, such as ALLOW_SNAPSHOT_ISOLATION, from the model database.

Only one file group in tempdb is allowed for data and one file group for logs. You can configure the size of the files. When auto grow is enabled (which is the default), the file grows until the disk volume is full. When the server restarts, the tempdb file size is reset to the configured value (the default is 8 MB). Auto grow is temporary for tempdb (unlike other types of databases). It is reset when SQL Server restarts.

Users can explicitly create and use tables in tempdb. Transactions can be used to modify data in the tables. Transactions can be rolled back. However, there is no need to REDO them because the contents of tempdb do not persist across SQL Server restarts. Because the transaction log does not need to be flushed, transactions are committed faster in tempdb than in user databases. In a user database, transactions have the ACID attributes: atomicity, concurrency, isolation, and durability. In tempdb, transactions lose the durability attribute.

SQL Server uses tempdb to store internal objects such as the intermediate results of a query. Most of these internal operations on tempdb do not generate log records because there is no need to roll back. So, these operations are faster.

 

For more details please refer to this link : http://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspx
Thanks,
Web Editor

TSQL Script to maintain indexes based on fragmentation

Suppose you want to loop through all indexes and rebuild those which fragmentation exceeds 30 percent, and reorganize those which fragmentation is between 5 and 30 percent. Rebuilding or reorganizing all indexes is not a problem – you can prepare a maintenance plan and incorporate a particular task. But it will not solve the problem – this way you can apply only action to all the indexes in a database. You can say there is no problem in rebuilding all indexes, but there is – there is no point rebuilding those which are barely fragmented since it is a waste of resources (disk space, CPU and I/O), extra log space is being used to record all the operations and it may not give any performance boost at all. On the other hand – reorganizing some indexes may give no performance bonus, especially at high level of fragmentation, when it’s easier (and better) to rebuild.

So the problem stated in the beginning may be solved this way:

  1. Extract information about all indexes to be maintained (note that the scope can be narrowed to a single table) – you need index name, table name and fragmentation.
  2. For each index perform rebuild or reorganization based on fragmentation.
  3. (optional) Place it in a maintenance plan (in Execute T-SQL Statement Task) or SQL Server Agent job to run it periodically.

Here is the TSQL code for reference:

————————————————–

DECLARE @IndexName varchar(255)
DECLARE @TableName varchar(255)
declare @Frag float

DECLARE TableCursor CURSOR FOR
SELECT si.[name] as index_name,
    sdm.avg_fragmentation_in_percent,
    so.[name] as table_name
FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL, NULL, NULL) sdm
    inner join sys.indexes si on sdm.object_id = si.object_id and si.index_id = sdm.index_id
    inner join sys.objects so on so.object_id = si.object_id

OPEN TableCursor 

FETCH NEXT FROM TableCursor INTO @IndexName, @Frag , @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
    print @TableName + ' - ' + @IndexName + '...'
    if @Frag < 30 and @Frag > 5
    begin
        print ' REORGANIZE '
        exec ('ALTER INDEX ' + @IndexName + ' ON [' + @TableName + '] REORGANIZE')
    end
    else if @Frag > 30
    begin
        print ' REBUILD '
        exec ('ALTER INDEX ' + @IndexName + ' ON [' + @TableName + '] REBUILD')
    end
    print 'done' + char(13)
    FETCH NEXT FROM TableCursor INTO @IndexName, @Frag, @TableName
END 

CLOSE TableCursor
DEALLOCATE TableCursor

The SharePoint 2010 SP1 Content Database Data Size Limit

The SharePoint Content Database Data Size Limit

With the release of SharePoint 2010 SP1 and some new guidance we are changing the supported data size limits for SharePoint content databases. Prior to SP1 the content database limit was 200 GB for collaboration and 1 TB for document archive. The content database size includes both metadata and BLOBs regardless of where the BLOBs are located and use of RBS does not bypass or increase these limits.
The new guidance for supported content database size details outlines specific guidance for SharePoint administrators as the data size grows. If this new guidance is followed SharePoint can support up to 4 TB of data in all usage scenarios and has no imposed size limit for document archive scenarios. The details are in the TechNet document SharePoint Server 2010 capacity management: Software boundaries and limits and the primary changes are:
  1. For a SharePoint content database up to 200 GB there are no special requirements and this limit is included for consistency.
  2. For a SharePoint content database up to 4 TB you need to additionally plan for the following two requirements:
    • Requires disk sub-system performance of 0.25 IOPS per GB, 2 IOPS per GB is recommended for optimal performance.
    • Requires the customer to have plans for high availability, disaster recovery, future capacity, and performance testing.
    • And you need to review additional considerations in the TechNet Boundaries and Limits article.
  3. For a SharePoint content database over 4TB specifically for a Document Archive scenario you are required to additionally plan for the following:
    • SharePoint sites must be based on Document Center or Records Center site templates and must be an archive scenario where less than 5% of content is actively read from each month and less than 1% of content is actively written to.
    • Do not use alerts, workflows, link fix-ups, or item level security on any SharePoint objects in the content database. Note: document archive content databases can be the recipient of documents as a result of Content Routing workflow.
  4. Other specific limits changes being made at the same time:
    • A new limit of 60million items in any one SharePoint content database
    • The specific 5 TB limit per SQL Server instance has been removed. Instead you should work with a SQL Server professional to plan for database storage.

Sharepoint 2010 – Introduction to some important terminologies

SharePoint is a Microsoft platform that allows people to build websites. SharePoint 2010
is the fourth version of SharePoint from Microsoft, and it is also known as SharePoint
v4 or Microsoft Office SharePoint Server 2010. It is very different from the versions
that came before it.

SharePoint
allows people to create websites with different content and different purposes.
Its many built-in features and components make it a comprehensive solution that
can fit many needs.

Some important terminologies that are usually used in SharePoint
environment are explained/defined below briefly:

What Is Microsoft FAST Search?

FAST is an optional component of SharePoint Server that an organization can have installed
on top of SharePoint. It adds further intelligence to the regular SharePoint search experience by enhancing the search options and how the search results are returned.
If FAST is installed on a SharePoint site, you see more options than you would
normally get in SharePoint. Chapter 4, “Searching in SharePoint,” provides some
examples of these options.

What Is a Site?

The structure of SharePoint sites (sometimes referred to as webs) is very different from the structure of typical Internet sites that contain only pages. In SharePoint, a site can house more than just pages. It is a container that holds lists and libraries and it can have other sites under it.

What Is a List?

A SharePoint list is a container for information, similar to a very simple database or spreadsheet.
Using a list is the most common way to manage information in a SharePoint site. In a list, data is gathered in rows, and each row is known as a list item. A list can have multiple
columns—also known as properties, fields, or metadata. So a list item is a row with data in those columns.

Different lists can have different security settings. For example, list managers can define who is allowed to add items to a list, who is allowed to edit items, who is allowed to read the items, and so on. Similarly, each list item can have its own security settings, so different list items can be visible to different people. For example, an item that is a link to a restricted site can have security settings that prevent users who don’t have access to that site from seeing it.

In some lists, you can attach files to list items—very much like attachments in e-mail.
For example, in a contacts list, you could attach to each contact a picture and a resume. Or in a list of tasks, you might attach documentation of what needs to be done to the task.
What Is a Content Type?

lists and document libraries can store different kinds of content, known as content types.

 A site manager can create and manage the content types in a site. The content types are then available in that site and in all the sites under it. The different types of content may have different site columns and/or different settings, such as policies and workflows, associated with them.

Content types can use site columns only for column definitions. This means that to create a content type, you must choose what site columns should be included in that content type.

What Is an External List?

An external list is unlike other SharePoint lists. Strictly speaking, it is not a SharePoint list at all because it doesn’t store information inside it. An external list is a view on external
data—that is, data that is contained not within SharePoint but in external databases and systems. When you add external lists to SharePoint sites, they are displayed in an interface
that looks almost exactly like a regular SharePoint list. An external list also allows most of the same interactions with the items in the list that are offered with a regular SharePoint
list. This book does not cover external lists because they are an advanced feature of SharePoint 2010 that is created and configured by developers while usually looking and feeling the same as regular lists for you, the end user.

What Is a Document Library?

A document library a special instance of a list, in which every list item is a file. Files can be Microsoft Office documents, Adobe Acrobat documents (PDF files), or any other type of file that the system administrator allows. This book often refers to document libraries as simply libraries. Most of the attributes of lists exist in document libraries. In fact, lists and documents libraries are similar in many ways. However, each item in a document library is a file. Therefore, when creating a new item in a document library, you need to either upload a file or create one.

Additionally, unlike in lists, in document libraries, each row can hold only one file.

There isn’t an option to attach more files to the row. Essentially, the file itself is the row.

Also, because a file can be downloaded, visitors to document libraries have different options available to them when browsing a document library than they have with lists.

Because document libraries and lists have so much in common, many instructions throughout this book apply to both. Where appropriate, the text makes clear that the instructions are for both.

What Is a Wiki Page Library?

A wiki page library is a special instance of a document library that is designed
to store web pages. On those web pages, you can display different types of content—text, images, videos, and web parts.

What Is a Form Library?

A form library is much like a document library, but it is supposed to host only Microsoft  InfoPath forms. Microsoft InfoPath is electronic form-creation software that integrates with SharePoint. Forms created with InfoPath can be published to SharePoint form libraries, and users can then fill out these forms.

What Is an Asset Library?

An  asset library is a special instance of a document library that is specially designed to store digital assets such as images, audio files, and videos.

What Is a Slide Library?

A slide library is a special type of library that has features not available in other types. This is  to create PowerPoint presentations by sharing slides. One user can allow other  users to import those slides into their presentations.

What Is a Picture Library?

A picture library is a special type of a document library that is dedicated to images. A picture  library is useful for sharing photos with other people. For example, you can have  a picture library as your stock photo repository

 What Is a View?

Using  views is a useful way for a list manager to create different ways to show the information  in a list or library. Different views may show different columns and have different sorting and filtering, grouping, and styles. In SharePoint, views can be either public or private:

. Public—The list’s or library’s managers create  public views, and these views are  available to anyone to use.

. Private—Users create private views. Only the user who created a private view can  use that view. You may, for example, create a private view and customize it to  show the information that you usually need to find the items or files that you usually  work with.

What Are Web Parts?

Web parts are the building blocks of pages in SharePoint. They are components that show data, and they can be placed in certain regions of a page—known as web part zones.
A page can hold many web parts, in different zones or in the same zone. They may be one under another in some zones and side-by-side in other zones

What Are Alerts?

Using alerts is a great way to be notified by e-mail of changes in lists and libraries or even specific documents or list items.

SharePoint has a built-in alert mechanism that enables users to register for different kinds  of alerts. Basically, a user selects the piece of content she wants to be alerted on and
requests that SharePoint send her an e-mail when that content changes.

What Is a Site Column?

A site column is a column for a list or a document library that can be used in all document  libraries or lists in the site in which it is created, as well as in the subsites for that site.

A site manager can define a specific column of data once and manage it from a central location instead of creating that column many times in many lists and libraries. In addition, content types can only use site columns. (In lists and libraries, on the other hand, columns can be created separately.)

 What Is a Content Type?

As mentioned earlier in this chapter, lists and document libraries can store different kinds of content, known as content types. A site manager can create and manage thecontent
types in a site. The content types are then available in that site and in all the sites under it. The different types of content may have different site columns and/or different
settings, such as policies and workflows, associated with them. Content types can use site columns only for column definitions. This means that to create a content type, you must choose what site columns should be included in that content type

What Is Tagging?

Tagging is a social web mechanism available in Microsoft SharePoint 2010 Server (not in SPF) that enables you as the user to tag a document or a list item or a even a page in the SharePoint site or outside it.

You can tag something to help remember it and find it more easily later on. One tag that SharePoint comes with is the I Like It tag. This tag enables you to signify that you like a document or a page, and then other people can see that you liked it.  You can easily find that document or page again by looking at the list of items you’ve tagged  as things you like (usually from your personal site).

What Is Managed Metadata?

Available only through Microsoft SharePoint 2010 Server (not SPF), managed metadata is a mechanism that enables administrators to create hierarchical term sets that can then be used in document libraries and lists as columns. A term set is similar to a list that contains items, except that these items can contain more items under them in a hierarchy. For example, if you have a term set called Products, you could have a term for each product that you have in the organization. By  using managed metadata, you can create the list as a hierarchical list,  grouping the products into categories (creating terms for the categories and then terms for the products under them) or into product groups

What Does Check-in/Check-out Mean?

Check-in and check-out are common terms in many document management systems,including SharePoint. Their purpose is to prevent conflicts in an environment where multiple people might want to edit the same piece of content (in SharePoint, list items or  files) at the same time. The term check-in describes the process of adding a new or modified item or file to a document library or a list to replace the previous version. The term  check-out describes  the process of getting a version of a document or list item in a list  or library. By checking out an item or a file, a user can prevent others from editing that  content. By checking in the item, the user can allow others to edit the  content, without needing to worry about overriding changes that others have made.

Usually when an item or a file is checked out to a user, that user can work on that item or file, and other users cannot. Other users must wait for the user to check in the item or file again (that is, perform a check-in) before they can edit the item or file. While the item or file is checked out, other users usually can see only the last version that was checked in; they can’t see the changes that the current user has made on the file while it’s been checked out.

 What Is a Workflow?

In SharePoint, a workflow is a series of steps—some automatic, some manual—that must  be performed as part of a business process for a document or a list item.SharePoint is a Microsoft platform that allows people to build websites. SharePoint 2010 is the fourth version of SharePoint from Microsoft, and it is also known as SharePoint v4 or Microsoft Office SharePoint Server 2010. It is very different from the versions that came before it. SharePoint allows people to create websites with different content and different purposes. Its many built-in features and components make it a comprehensive solution that can fit many needs.

 

Thanks for reading.