Database

Quick Search

SQL Expressions/Examples

June 29th, 2010 by admin
4 comments »

Creating a Database

To create a database in SQL, use the following syntax:

CREATE DATABASE DatabaseName

Here is an example:

CREATE DATABASE BethesdaCarRental;
Deleting a Database

To delete a database, you use the DROP DATABASE expression followed by the name of the database. The formula used is:

DROP DATABASE DatabaseName;

Here is an example:

DROP DATABASE RealEstate1;
GO

Renaming a Database

To … Read More

Count number of words in a MySQL column

March 5th, 2010 by admin
6 comments »

This is a general requirement to count number of words in a column of a MySQL database table. But MySQL does not have any built in function to count number of words as it generally has for number of purposes.

But you can do it with a simple trick e.g. you … Read More

Bind multiple rows value in a single row

February 27th, 2010 by admin
No comments »

Following example demonstrate that how you can bind multiple rows value in a single row. Through this query you got comma (,) separated value in a single row.   
 
 
Example:-
 
declare @a varchar(500)
set @a = ‘ ‘
select @a = @a + cast(id as varchar(20)) + ‘,’ from dbo.TR_UserBasic
if len(@a)>1
set @a= left(@a,len(@a)-1)
select case … Read More

How execute store procedure with C#.net

February 27th, 2010 by admin
1 comment »

Create store procedure in sql query analyser

CREATE PROCEDURE sp_chkadmin
@login_id varchar(50),
@password varchar(50)
as begin
select * from where login_id = @login_id and password =@password
end

GO

protected void butlogin_ServerClick1(object sender, EventArgs e)
{

string username = txtlogin.Value.ToString().Replace(“‘”, “””);
string password = txtpassword.Value.ToString().Replace(“‘”, “””);
int isUserExist=0;
isUserExist = IsUserExist(username, password);
if (isUserExist == 1)
{
Session["admin"] = username;
Response.Redirect(“next.aspx”);
}
else
{
lblhead.Text = “Please Enter Correct Username or Password … Read More

How use trigger in sql

February 27th, 2010 by admin
No comments »

Example of Delete trigger

CREATE trigger [TRIGGER_Deletesubcategory] ON dbo.category

FOR delete

AS

declare @nmid int

select @nmid=sno from deleted

delete from subcategory where cat_id= @nmid

There will be two table one is category and second one is subcategory and the primery key of category table will be sno and the this will foreign key(cat_id) for subcategory table.