Tuesday, August 30, 2011

SQL SERVER 2008

http://blogs.msdn.com/b/bethmassi/archive/2011/02/18/step-by-step-installing-sql-server-management-studio-2008-express-after-visual-studio-2010.aspx

Storing and Retrieving Image in SQL Server

http://chiragrdarji.wordpress.com/2007/03/05/storing-and-retrieving-image-in-sql-server/
Creating Stored Procedures and User-Defined Functions with Managed Code

http://www.asp.net/data-access/tutorials/creating-stored-procedures-and-user-defined-functions-with-managed-code-cs

Rapid Application Development Using InfoPath and BCS – Part


http://blogs.msdn.com/b/sharepointdev/archive/2011/07/26/rapid-application-development-using-infopath-and-bcs-part-2-anweshi-deverasetty.aspx

***************************************************************
Stored procedure.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Stored Procedure Test.aspx.cs" Inherits="Stored_Procedure_Test" %>












































Stored procedure.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Stored_Procedure_Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConnection = new SqlConnection("Data Source = 110.291.58.20;Failover Partner=crmdb; Initial Catalog =DEV_MSCRM;User Id=crma;password=password");

try
{
// string SpName;

DataSet ds = new DataSet();

sqlConnection.Open();

SqlCommand sqlcommand = new SqlCommand( "udsp_GetOppRelatedUsers" , sqlConnection);
//sqlcommand.CommandText = "SpName";
sqlcommand.CommandType = CommandType.StoredProcedure;
sqlcommand.Parameters.Add("@opportunityId", SqlDbType.VarChar, 50);
sqlcommand.Parameters["@opporId"].Value = "DA9BED-EB69-DE11-BBF4-000E0C440577";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcommand;
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
TextBox1.Text = ds.Tables[0].Rows[10][1].ToString();
Response.Write(sqlConnection.State.ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqlConnection.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string sqlstr = "Data Source =50.2051.185.25;Failover Partner=crmdb; Initial Catalog =DEV_MSCRM;User Id=cra;password=password";
SqlConnection sqlConnection = new SqlConnection(sqlstr);
try
{
// string SpName;
DataSet ds = new DataSet();
sqlConnection.Open();
SqlCommand sqlcommand = new SqlCommand("udsp_GetOppRelatedUsers", sqlConnection);
//sqlcommand.CommandText = "SpName";
sqlcommand.CommandType = CommandType.StoredProcedure;
sqlcommand.Parameters.Add("@opportId", SqlDbType.VarChar, 50);
sqlcommand.Parameters["@opportId"].Value = "5D4EB3AD-751D-DD11-94A3-000E0C440405";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcommand;
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
Response.Write(sqlConnection.State.ToString());
// TextBox1.Text = ds.Tables[0].Rows.Count.ToString();
}
catch (Exception ex)
{
Response.Write(sqlstr +"\t\t"+ ex.Message);
}
finally
{
sqlConnection.Close();
}
}
public void addusers(int i)
{
try
{
SqlConnection sqlConnection = new SqlConnection("Data Source = dev;Failover Partner=tracb; Initial Catalog =MSCRM_CUSTOM;User Id=ADmin;password=password@");
sqlConnection.Open();
SqlCommand sqlcommand = new SqlCommand("udsp_GetOppRelatedUsers", sqlConnection);
//sqlcommand.CommandText = "SpName";
sqlcommand.CommandType = CommandType.StoredProcedure;
sqlcommand.Parameters.Add("@opportunityId", SqlDbType.VarChar, 50);
sqlcommand.Parameters["@opportunityId"].Value = "5D4EB3AD-751D-DD11-94A3-000E0C440405";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = sqlcommand;
DataSet ds = new DataSet();
da.Fill(ds);

//// usr.LoginName = crmloginuser(userGuid);
//for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) //{ // string s = "HELLO" + Label2.Text; // usr.LoginName = s + ds.Tables[0].Rows[i][1].ToString(); // string strtitle = grps[0].Title; // grpuser.Users.Add(usr); // ctx.ExecuteQuery(); //} } catch (Exception Ex) { } } } **************************** Interview Question: Difference Between GETDATE and SYSDATETIME
When we use GETDATE the precision is till miliseconds and in case of SYSDATETIME the precision is till nanoseconds.
What do you mean by SQL Posting
we can say Posting is an events that helps to writes Inserts,Updates and Deletes in the forms to the database but not commit this transaction to the databases.
What is Filtered Index in SQL
This index is used when we have to index some of rows in table this helps to increase performance and also reduce cost done by index on all the rows.When we see an Index created with some where clause then that is actually a FILTERED INDEX.
What is Linked Server in SQL Server
Linked Servers is SQL Server concept by we can add more SQL Server to a Group and query both the SQL Server dbs usig TSQL Statements. With the help of linked server we can create very fresh,clean, easy to follow, SQL statements that allow remote data to be retrieved, joined and combined with local data. These two Stored Procedure sp_addlinkedserver, sp_addlinkedsrvlogin will be used add new Linked Server.
Define some facts about Temporary table and there types
Temporary table name is limited t 116 characters. Local temporary table created with single # and then name of table. And this table is to be deleted explicitly and if it is created in store procedure it will be dropped at the end of store procedure. On the other hand if are talking abut Global variable tables start with ## and these are dropped on the session ends. And some more facts about the Temporary tables is that these cannot be partitioned and we c
annot create key constraints to these tables and one more thing is that we cannot create user-defined data types in tempdb.

How to get number of Maximum connection can be establish to SQL
select @@MAX_Connections
Why we use Unicode In Sql server
Unicode data is stored using the nchar, nvarchar,and ntext data types in SQL Server. Use these data types for columns that store characters from more than one character set. The SQL Server Unicode data types are based on the National Character data types in the SQL-92 standard.
Diffrence between temp table and table variable
1)Temp Tables are created in the SQL Server TEMPDB database and therefore require more IO resources and locking. Table Variables and Derived Tables are created in memory.
(2)Temp Tables will generally perform better for large amounts of data that can be worked on using parallelism whereas Table Variables are best used for small amounts of data (I use a rule of thumb of 100 or less rows) where parallelism would not provide a significant performance improvement.
(3)You cannot use a stored procedure to insert data into a Table Variable or Derived Table. For example, the following will work: INSERT INTO #MyTempTable EXEC dbo.GetPolicies_sp whereas the following will generate an error: INSERT INTO @MyTableVariable EXEC dbo.GetPolicies_sp.
(4)Derived Tables can only be created from a SELECT statement but can be used within an Insert, Update, or Delete statement.
(5) In order of scope endurance, Temp Tables extend the furthest in scope, followed by Table Variables, and finally Derived Tables
What is SQL injection
SQL injection is a security vulnerability that occurs in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is in fact an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another.
Write some disadvantage of Cursor
Cursor plays there row quite nicely but although there are some disadvantage of Cursor . Because we know cursor doing roundtrip it will make network line busy and also make time consuming methods. First of all select query gernate output and after that cursor goes one by one so roundtrip happen.Another disadvange of cursor are ther are too costly because they require lot of resources and temporary storage so network is quite busy.
What is different in Rules and Constraints
Rules and Constraints are similar in functionality but there is a An little diffrence between them.Rules are used for backward compatibility . One the most exclusive diffrence is that we an bind rules to a datatypes whereas constraints are bound only to columns.So we can create our own datatype with the help of Rules and get the input according to that.
What Is Database
A database is similar to a data file in that it is a storage place for data. Like a data file, a database does not present information directly to a user; the user runs an application that accesses data from the database and presents it to the user in an understandable format.Database systems are more powerful than data files in that data is more highly organized. In a well-designed database, there are no duplicate pieces of data that the user or applicati
on must update at the same time. Related pieces of data are grouped together in a single structure or record, and relationships can be defined between these structures and records.When working with data files, an application must be coded to work with the specific structure of each data file. In contrast, a database contains a catalog that applications use to determine how data is organized. Generic database applications can use the catalog to present users with data from different databases dynamically, without being tied to a specific data format. A database typically has two main parts: first, the files holding the physical database and second, the database management system (DBMS) software that applications use to access data. The DBMS is responsible for enforcing the database structure, including: � Maintaining relationships between data in the database. Ensuring that data is stored correctly, and that the rules defining data relationships are not violated. � Recovering all data to a point of known consistency in case of system failures.

what is Relational Database
Although there are different ways to organize data in a database, relational databases are one of the most effective. Relational database systems are an application of mathematical set theory to the problem of effectively organizing data. In a relational database, data is collected into tables (called relations in relational theory). A table represents some class of objects that are important to an organization. For example, a company may have a database w
ith a table for employees, another table for customers, and another for stores. Each table is built of columns and rows (called attributes and tuples in relational theory). Each column represents some attribute of the object represented by the table. For example, an Employee table would typically have columns for attributes such as first name, last name, employee ID, department, pay grade, and job title. Each row represents an instance of the object represented by the table. For example, one row in the Employee table represents the employee who has employee ID 12345. When organizing data into tables, you can usually find many different ways to define tables. Relational database theory defines a process called normalization, which ensures that the set of tables you define will organize your data effectively.

What is COMMIT and ROLLBACK statement in SQL
Commit statement helps in termination of the current transaction and do all the changes that occur in transaction persistent and this also commits all the changes to the database.COMMIT we can also use in store procedure. ROLLBACK do the same thing just terminate the currenct transaction but one another thing is that the changes made to database are ROLLBACK to the database.
Can you tell me the difference between DELETE and TRUNCATE commands
Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.
What are the Global Temporary Tables
We can create global temporary tables but these are not using much in sql an the name of these table start with two pound signs. For example, ##interviewqsn is a global temporary table.As the name suggest these table is Global temporary tables and visible to all SQL Server connections. When we create any one of these all users can see it.
What is Cursor
Cursor is a database object used by applications to manipulate data in a set on a row-by-row basis, instead of the typical SQL commands that operate on all the rows in the set at one time. For example, you can use cursor to include a list of all user databases and make multiple operations against each database by passing each database name as a variable

No comments:

Blog Archive