Once a database exists on the server, to use it, you must first establish a connection to it. To programmatically connect to a Microsoft SQL Server database, you could use a SqlConnection variable. In the connection string, to specify the database, assign its name to the Database attribute. Once you have established a connection, you can then open it and perform the desired actions: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; |
|
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection connection = new SqlConnection("Data Source=(local);" + "Database='Exercise';" + "Integrated Security=yes;"); SqlCommand command = new SqlCommand(SQL Code, connection); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
If you have created a database but don't need it anymore, you can delete it. To delete a database in SQL, you use the DROP DATABASE instruction followed by the name of the database. The formula used is: DROP DATABASE DatabaseName Before deleting a database in SQL, you must make sure the database is not being used or accessed by someone else or by another object.
When you install Microsoft SQL Server, it also installs 5 databases named master, model, msdb, and tempdb. These databases will be for internal use. This means that you should avoid directly using them, unless you know exactly what you are doing.
One of the databases installed with Microsoft SQL Server is named master. This database holds all the information about the server on which your Microsoft SQL Server is installed. For example, we saw earlier that, to perform any operation on the server, you must login. The master database identifies any person, called a user, who accesses the database, about when and how. Besides identifying who accesses the system, the master database also keeps track of everything you do on the server, including creating and managing databases. You should not play with the master database; otherwise you may corrupt the system. For example, if the master database is not functioning right, the system would not work.
You can establish a connection to the server using a user account that can use the server. In Microsoft SQL Server, the user who creates a database is referred to as the database owner. To identify this user, when Microsoft SQL Server is installed, it also creates a special user account named dbo. This account is automatically granted various permissions on the databases of the server. Because the dbo account has default access to all databases, to refer to an object of a database, you can qualify it by typing dbo, followed by the period operator, followed by the name of the object. |
|