You are here
Home > Sql Server > SQL Syntax

SQL Syntax

SQL Syntax

  • SQL follows unique set of guidelines and rules called syntax.
  • SQL is case insensitive.
  • SQL statements start with any of the keywords/ commands like CREATE, DROP, INSERT, UPDATE, DELETE, SELECT, ALTER, USE etc.
  • Here, we are gives you all the basic sql syntax.

Create database:

create database database_name;

Create table:

create table <tablename>

( <columnname><datatype>(size));

Select Statement:

select * from tablename;

OR

select columnname1, columnname2,…., columnnameN  from tablename;

Insert Statement:

insert into table_name

values(value1, value2,….. ,valueN);

OR

insert into table_name (column1,column2,…..,columnN) values(value1, value2,….. ,valueN);

Update Statement:

update <table_name>

set <column1>=<expression1>, <column2>=<expression2>,…., <columnN>=<expressionN>

where condition;

Delete Statement:

delete from <table_name>

where condition;

Insert into Select Statement:

insert into table_name2

select * from table_name1

where condition;

  • Insert columns from one table to another table.

 

insert into table_name2(column1,column2,…., columnN)

select (column1, column2,…., columnN)

from table_name1

where condition;

Distinct:

select distinct column-list from <tablename>;

Drop table:

drop table tablename;

Truncate table:

Truncate table tablename;

Alter table:

alter table tablename modify|add|drop columnname <datatype> (size);

Use Statement:

use database_name;

Commit Statement:

commit;

Rollback Statement:

rollback;

Count:

select count(*) from tablename

where condition;

Where clause:

select * from tablename

where condition;

Order by clause:

select * from tablename

where condition

order by columnname asc|desc;

Group by clause:

select aggregate_function(columnname)

from tablename

where condition

group by columnname;

Having clause:

select aggregate_function(columnname)

from tablename

where condition

group by columnname

having condition;

AND|OR clause:

select * from tablename

where condition-1

AND|OR condition-2;

IN clause:

select * from tablename

where columnname IN(val-1,val-2,….,val-N);

Between clause:

select * from tablename

where columnname between val-1 and val-2;

Like clause:

select * from tablename

where columnname like pattern;

Create index:

create index index_name

on tablename (column1, column2,…., columnN);

Drop index:

drop index index_name

on tablename;

Drop database statement:

drop database databasename;

 

 

Keep visiting my site ask2tech.com for upcoming top technical article

Learn more about DBA at TechNet Consultancy

Leave a Reply

Top