Friday, 12 July 2013

basic Syntax in sql server

Hi ,

           SQL is followed by unique set of rules and guidelines called Syntax. This Article gives
you a quick start with SQL by listing all the basic SQL Syntax: All the SQL statements start
with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP,
CREATE, USE, SHOW and all the statements end with a semicolon (;). Important point
to be noted is that SQL is case insensitive which means SELECT and select have same meaning
in SQL statements but MySQL make difference in table names. So if you are working with
MySQL then you need to give table names as they exist in the database.


SELECT Statement:

SELECT column1, column2....columnN FROM table_name;

DISTINCT Clause:

SELECT DISTINCT column1, column2....columnN FROM table_name;

WHERE Clause:

SELECT column1, column2....columnN FROM table_name WHERE CONDITION;

AND/OR Clause:

SELECT column1, column2....columnN FROM table_name WHERE CONDITION-1 {AND|OR} CONDITION-2;

IN Clause:

SELECT column1, column2....columnN FROM table_name WHERE column_name IN (val-1, val-2,...val-N);

BETWEEN Clause:

SELECT column1, column2....columnN FROM table_name WHERE column_name BETWEEN val-1 AND val-2;

Like :

SELECT column1, column2....columnN FROM table_name WHERE column_name LIKE { PATTERN };

ORDER BY :

SELECT column1, column2....columnN FROM table_name WHERE CONDITION ORDER BY column_name {ASC|DESC};

GROUP BY :

SELECT SUM(column_name) FROM table_name WHERE CONDITION GROUP BY column_name;

COUNT :

SELECT COUNT(column_name) FROM table_name WHERE CONDITION;

HAVING :

SELECT SUM(column_name) FROM table_name WHERE CONDITION GROUP BY column_name HAVING (arithematic function condition);

CREATE TABLE Statement::

CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );

DROP TABLE Statement::

DROP TABLE table_name;

CREATE INDEX :

CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,...columnN);

DROP INDEX :

ALTER TABLE table_name DROP INDEX index_name;

TRUNCATE :

TRUNCATE TABLE table_name;

ALTER :

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

Statement (Rename):

ALTER TABLE table_name RENAME TO new_table_name;

INSERT INTO :

INSERT INTO table_name( column1, column2....columnN) VALUES ( value1, value2....valueN);

UPDATE:

UPDATE table_name SET column1 = value1, column2 = value2....columnN=valueN [ WHERE CONDITION ];

DELETE Statement:

DELETE FROM table_name WHERE {CONDITION};

CREATE DATABASE :

CREATE DATABASE database_name;

DROP :

DROP DATABASE database_name;

USE :

USE DATABASE database_name;



I hope You got something useful in this article. I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.


Related Posts

Group by in sql server
Pivot Unpivot data in sql server
Combine two or more column in one column in sql sever
rank fuctions in sql
Get month wise Number of working
Take Back up of table using select statement in sql server
Column data in comma seprated string
Delete duplicate records from table
Date function in sql server
Sql server::String with initial letter in uppercase.
Joins in Sql server
Dynamic Query in sql server
Basic About View
send sql table data via email using store procedure
How to use Store Procedure inside a store procedure
SET ANSI_NULLS in sql server
SET QUOTED_IDENTIFIER in sql
example of Cursor in sql server
basic of Cursor in sql.
delete duplicate records in sql server
select duplicate records in sql server
update duplicate records in sql server
comman table expression(CTE) in sql server
Split Funtions in sql server
Sql queries for sql server
Trigger on Update
Trigger on insert
trigger on delete
basic of trigger
insert into view with multiple tables
Insert into View in sql server
Interview queries in sql server
update data in view with multiple table
Update view with single table
Group by in sql server
pivot without aggregate function in sql
loop in sql server
get monthwise calender in sql server
temp table and temp variable in sql server

No comments:

Post a Comment

8451831077