Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Saturday, March 12, 2011

FULL or LEFT JOIN

The FULL / LEFT JOIN keyword returns all rows from the left table (table 1), even if there are no matches in the right table (table 2).

Table 1: adetails


Table 2: assignto


Query:
select adetails.*, assignto.*  
    from adetails FULL JOIN assignto  
    on adetails.machine_sno=assignto.machine_sno

    or

    select adetails.*, assignto.*  
    from adetails LEFT JOIN assignto  
    on adetails.machine_sno=assignto.machine_sno
Result:


JOIN or INNER JOIN

INNER JOIN is the same as JOIN.
The INNER JOIN keyword return rows when there is at least one match in both tables.

Table 1: adetails
adetails

Table 2:  Orders


Query:
select adetails.*, assignto.* 
    from adetails JOIN assignto 
    on adetails.machine_sno=assignto.machine_sno

    or
    select adetails.*, assignto.*
    from adetails INNER JOIN assignto 
    on adetails.machine_sno=assignto.machine_sno
Result:

Check Size of your Database

This command will help you for checking the Database space, Here Database Name is login.

Command:    Exec sp_spaceused

Result
 

Comment


create table alertclub  /* Creating a Table is a comment*/
(
    uname varchar(20),
    phoneno varchar(10),
    address varchar(20)
)

Select columns from Table



Type 1: For select all column from table alertclub
Select * from alertclub

Type 2: For select Particular column from table, suppose if you want to select uname (column name) from 
 alertclub  (table name). then execute this query:

Select uname from alertclub

Rename Table Name


Suppose your table is alertclub and you will change it to AC

Step 1: Execute this query:
EXEC sp_rename 'alertclub', 'AC'
 After execute this query, one msg will come out like this:
Caution: Changing any part of an object name could break scripts and stored procedures.
Step 2: select * from AC 
Table name raname from alertclub to AC



Rename Column Name


Before rename column name

Step 1: sp_rename 'alertclub.uname', 'username'

After excute this query one msg will come like this:

Caution: Changing any part of an object name could break scripts and stored procedures.

and open table
Step 2:  select * from alertclub

you will see that column name changed from uname to username

After Rename column name


Sunday, February 27, 2011

Use existing Database


use alertclub

This Commad is use for selecting the Existing Database.
Here alertclub is a name of Database

Delete Database


drop database alertclub

If you want use it then it show message Like:

Msg 911, Level 16, State 1, Line 1
Could not locate entry in sysdatabases for database 'ram'. No entry found with that name. Make sure that the name is entered correctly.


Update Values in Table

The UPDATE statement is used to update existing records in a table.




update log1 set uname='alertclub' where class='ABC'


Note: XYZ value update to alertclub

Truncate Table

What if we only want to delete the data inside the table, and not the table itself?
Then, use the TRUNCATE TABLE statement:
For Example:

Before Truncate
Truncate Table log1





Delete Column from Table


Here we are deleting column pas

Before Drop
Alter table log1 drop column pas

After Drop

Add New Column in a Table



Before Alter

 Alter table log1 add class varchar(10);

After Alter

Note: Here Table Name is log1

Tuesday, January 4, 2011

Drop Table

select * from table1;
drop table table1; 
select * from table1;



This message Shown Because Table1 deleted from database.

Thursday, December 30, 2010

Delete Row from Table


Before deleting row

DELETE FROM table1 WHERE 
first_name='akshay';

select * from table1;

Output---->
After deleting row

Insert value into table

This summary is not available. Please click here to view the post.

Tuesday, December 28, 2010

Create Table


create table table1
(
   first_name char(30),
   last_name char(30),
   contact_no int,
   email_id varchar(20)
);

select * from table1;

Output--->

Create Database

create database alertclub;