Showing posts with label Latest Post. Show all posts
Showing posts with label Latest Post. Show all posts

Friday, January 27, 2012

SQL Server :- SQL INSERT INTO syntax


Hi dear fnds  welcome to know about sql insert into command :-

Its very easy follow  below note :-

The SQL INSERT INTO syntax has Two main use and the result of either of them is adding a new rows into the database table.
The first syntax and example form of the INSERT INTO SQL clause doesn't specify the column names where the data will be inserted, but just their values:
INSERT INTO Table1 VALUES (value1, value2, value3…)
insert into table2 values (1,'jaiverma','DBA')
The second form of the SQL INSERT INTO command, specifies both the columns and the values to be inserted in them:
INSERT INTO Table1 (Column1, Column2, Column3…)
VALUES (Value1, Value2, Value3…)
insert into table2 (employee_id, emp_name, emp_role)
values(1,'jaiverma','DBA')
As you might already have think, the number of the columns in the second INSERT INTO syntax form must match the number of values into the SQL statement; otherwise you will get an error.
If we want to insert a new row into our Address table, we are going to use one of the following Two SQL statements:

Database: Adventure Works
Schema: Person
Table: Address


1.

INSERT INTO address

VALUES (5, '1226 Shoe St.', 'India', 'Dehli',79,98011,'FBAFF93',

'1999-01-20 00:00:00.000')


2.

INSERT INTO

address(AddressID,AddressLine1,AddressLine2,City,StateProvinceID,

PostalCode,rowguid,ModifiedDate)

VALUES (5, '1226 Shoe St.', 'India', 'Dehli',79,98011,'FBAFF93',

'1999-01-20 00:00:00.000')
The result of the execution of either of the 2 INSERT INTO SQL statements will be a new row added to our Address database table.
 If you want to enter data for just a some of the table columns, you’ll have to use the second syntax form of the SQL INSERT INTO clause, because the first form will produce an error if you haven’t supplied values for all columns.
To insert only the AddressID and Addressline1 columns, execute the following SQL statement:
INSERT INTO

address(AddressID,AddressLine1) VALUES (5, '1226 Shoe St.')

Like and Share to SQL Integrity Blog

Wednesday, January 25, 2012

SQL SERVER :- WHERE Clause


SQL WHERE

IT IS VERY SIMPLE AND EASY TO LEARN ABOUT WHERE CLAUSE....

The SQL WHERE clause is used to select data conditionally, by adding it to already existing SQL SELECT query. We are going to use the address table, to illustrate the use of the SQL WHERE command.
Database: Adventure Works
Schema: Person
Table: Address

If we want to select all customers from our database table, having addressID '5' we need to use the following SQL Example:
Database: Adventure Works
Schema: Person
Table: Address

select * from AdventureWorks.Person.Address where AddressID =5

 -- or --
 select * from Address where AddressID =5



In this simple SQL query we used the "=" (Equal) operator in our WHERE criteria:
AddressID =5

But we can use any of the following comparison operators in conjunction with the SQL WHERE clause:
Database: Adventure Works
Schema: Person
Table: Address

<> (Not Equal)
select * from Address where AddressID <>5

> (Greater than)
select * from Address where AddressID >5

>= (Greater or Equal)
select * from Address where AddressID >=5

< (Less than)
select * from Address where AddressID <5

<= (Less or Equal)
select * from Address where AddressID <=5
LIKE (similar to)
 
select * from Address where Addressline1 like ‘1226 Shoe St.’
Note the LIKE syntax is different with the different RDBMS (SQL Server syntax used above). Check the sql Like  article for more details.
Between (Defines a range)
 
. select * from Address where AddressID between 5 and 10

Like and Share to SQL Integrity Blog

SQL Server :- DISTINCT Keyword


SQL DISTINCT
The SQL DISTINCT clause is used together with the SQL SELECT keyword, to return a dataset with unique entries for certain database table column.




For example if we want to select all distinct ReorderPoint from our Address table, we will use the following SQL DISTINCT statement:

SELECT DISTINCT LastName FROM Customers

Database: Adventure Works

Schema: Person

Table: Address

select distinct(ReorderPoint) from AdventureWorks.Production.Product
-or-
select distinct(ReorderPoint) from  Product

Like and Share to SQL Integrity Blog

Diff type of SELECT Command In sql


SQL SELECT
The SQL SELECT statement is used to select or fetch data from a SQL database table. This is usually the very first SQL command every SQL new person learns and this is because the SELECT SQL statement is one of the most used SQL commands.
Please have a look at the general SQL SELECT syntax and example:
Syntax:           SELECT Column1, Column2, Column3, FROM Table1
Database:       Adventure Works
Schema:          Person
Table:              Address
Query:            select AddressID,AddressLine1  from Person.Address



The list of column names after the SQL SELECT command determines which columns you want to be returned in your result set. If you want to select all columns from a database table, you can use the following SQL statement:

Database: Adventure Works
Schema: Person
Table: Address
Syntax:           SELECT * FROM Table1
Example:        select *  from Person.Address 
-or-
            select *  from Address 



When the list of columns following the SELECT SQL command is replaced with asterix (*) all table columns are returned. Word of caution here, it’s always better to explicitly specify the columns in the SELECT list, as this will improve your query performance significantly.
The table name following the SQL FROM keyword (in our case Table1) tells the SQL interpreter which table to use to retrieve the data.

Like and Share to SQL Integrity Blog