How to copy the tables, schema and views from one SQL Server to another?
There are multiple ways to do this.
1. "Detach Database" from one server and "Attach Database" to another server.
2. Manually script all the objects using SSMS and run the script on new server.
3. Use Wizard of SSMS.
How to copy data from one table to another table?
There are multiple ways to do this.
INSERT INTO SELECT
This method is used when table is already created in the database earlier and data is to be inserted into this table from another table. If columns listed in insert clause and select clause are same, they are not required to list them.
SELECT INTO
This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.
Friday, November 21, 2008
Copy in SQL Server
Multiple Insert in SQL Server
One ofthe v ery good feature of SQL Server 2008 is to insert multiple records at one using single INSERT statements.
INSERT INTO dbo.Departments
VALUES (1, 'Human Resources', 'Maryam'),(2, 'Sales', 'Biju'),
(3, 'Finance', 'Gilly'),(4, 'Purchasing', 'Barbera'),
(5, 'Manufacturing', 'Screwer');
Database connection in VB.NET
Many of the beginners doesnot have the basic idea of how to establish a database connection with Visual Studio Asp.net and SQL server.
Here is a small description of it.
(All the code is written in VB.Net)
1. When connecting to a database, first of all, you need two variables, one for connection and another for the sql commands.
Dim con As New Data.SqlClient.SqlConnection()
Dim cmd As New Data.SqlClient.SqlCommand()
2. You need a "connection" between design page and database
con.ConnectionString = "Data Source=;Initial Catalog=;Integrated Security=True"
Note: Integrated Security is used when "Windows Authentication" is used. If you use server authentication, then following code will be used
con.ConnectionString = "Data Source=;Initial Catalog=;uid=;pwd="
3. You need a command text
cmd.CommandText = ""
4. Establish a relation between command and the connection
cmd.Connection = con
5. Open the connection
con.open()
6. The actual operation is done in this step.
cmd.ExecuteNonQuery()
7. Close the connection
con.Close()
So thats it !!! You have done...
Here is an example of the above explanation :
Dim con As New Data.SqlClient.SqlConnection()
Dim cmd As New Data.SqlClient.SqlCommand()
con.ConnectionString = "Data Source=VJ\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=True"
cmd.CommandText = "INSERT INTO tblAddress(UName,Street,City) VALUES(@user,@street,@city)"
con.Open()
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
Differences Between Properties and Indexers in C#
Properties:
1)Identified by its name.
2)Accessed through a simple name or a member access.
3)Can be a static or an instance member.
4)A get accessor of a property has no parameters.
5)A set accessor of a property contains the implicit value parameter.
Indexers:
1)Identified by its signature.
2)Accessed through an element access.
3)Must be an instance member.
4)A get accessor of an indexer has the same formal parameter list as the indexer.
5)A set accessor of an indexer has the same formal parameter list as the indexer, in addition to the value parameter.
config files in .Net
Web.config:--Basically this file is use for web setting or we can say web.config file contains setting to a web application.
Machine.config:--Settings to a computer and that help to configure all application into same machine.
Example:--
In a machine it can be more then one web application so each application will have one or more web.config files depend on configuration level of folders but in that system there will be one machine.config file.
Overview of ASP.NET 3.5
ASP.NET has for long been a popular web application development platform. ASP.NET 2.0 added a lot of new features compared to its earlier counterpart, i.e., ASP.NET 1.1. With ASP.NET 3.5, you have even more features. This article will present the new features that have been added to ASP.NET and Visual Studio 2008.
In ASP.NET 3.5, a new tool has been introduced called the ASP.NET Merge Tool. You can use this tool for merging pre-compiled assemblies. No, this is not all. There isa lot of other exciting features and we will explore each of them as we progress through this article.
The most significant improvements in ASP.NET are:
* Integrated Ajax Support
* New Data Controls (ListView and DataPager)
* The LinqDataSource Control
Visual Studio 2008 has also included some features for an improved web application development experience. Here is the list of such improvements:
* Support for LINQ
* IntelliSense for JavaScript and ASP.NET Ajax
* Improved Design time experience
Please refer to below link for detailed explantion
http://aspnet.4guysfromrolla.com/articles/112107-1.aspx
Indexes in SQL Server
One of the common task in day-to-day life to resolve the performance issues with teh SQL queries. When there is a perfrmance issue with a Query that first thing that we do is Look for the QEP (Query Execution Plan). In this if any table is going for Full table scan then we want to know if there are indexes on that table or not. So below is the piece of code which can be used to list out all the indexes.
select name from sysindexes where id=object_id('Employees')
rename Column in SQL Server
The following sample code demonstrates how to rename a column in SQL server using the stored procedure
EXEC sp_rename
@objname = '[TableName].OldColumnName',
@newname = 'NewColumnName',
@objtype = 'COLUMN'
This stored procedure can also be used to rename the tables.
Computer Jokes
Struct professional
{
double styles;
Short skirts;
Void knowledge;
Char ununderstand;
}
Struct married
{
double weight;
Short tempered;
void speech;
Char unstable;
}
Struct engaged
{
double timeonphone;
Short attentiononwork;
Long boast;
Void understanding;
}
Struct newly_married_ females
{
double dinnerinvitation;
Short timeatwork;
Long lunchbreak;
Void bankbalance;
}
Struct husband_wife_ professionals
{
double income;
Short tempered;
Long notimesee_eachother;
Void life;
Char money_making;
}
Struct beautiful_city_ girl
{
double boyfriends;
Short affairs;
Long stories;
Void greymatter;
Char dating;
}
Struct old_lady
{
Short memory;
Long sighs ;
Void attention_from_ men;
}
Clear all Textboxes
In Our applications in most of the cases we have to clear all text boxes (when Cancel or Reset button is clicked)
This code is to clear all text boxes in the form .
Use This code in Button click event
public void imgcancel_Click(object sender, ImageClickEventArgs e) {
FindControl(Form.Controls);
}
'Find Control Method Definition
public static void FindControl(ControlCollection ChildCtrls)
{
foreach (Control Ctrl in ChildCtrls)
{
if (Ctrl is TextBox)
((TextBox)Ctrl).Text = "";
else
FindControl(Ctrl.Controls);
}
}