SQL Server
SQL Server
SQL COMMANDS
commit
savepoint -
rollback
/* create database */
/* select database */
use database_name;
use batch10;
/* datatypes */
6999999999
7999999999
char(15)
int
4) binary datatypes
1. binary (fixed binary length 8000 bytes)
2. varbinary (variable length 8000 bytes)
3. image
/* create table */
use batch10;
/* drop table */
/* drop database */
use admin;
drop database database_name;
use batch10;
/* create table */
address method
value method
/* address method */
/* value method */
use batch10;
/* update */
/* delete */
/* truncate */
/* SQL Operators */
1) Arithmetic Operators
a = 10 b = 20
1. Addition (+) a + b
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Modulus (%)
a = 10 b = 3
a/b = 10/3 =
2) Comparison Operators
a = 10; b = 5;
1. = a = b false
2. != a != b
3. > a > b
4. < a < b
5. >= a >= b
6. <= a <= b
9. <> a<>b
3) Logical Operators
1. ANY select * from product any (select * from order where productid =
10);
2. AND select * from student where marks > 80 and age < 16;
3. OR select * from student where marks > 80 or age < 16;
4. EXISTS
5. LIKE
6. BETWEEN - between [lowerrange] and [higherrange]
7. IN - columnname in('val1',...., 'valN')
'val' in(col1,col2,.....)
8. NOT
9. ALL
use batch10;
select * from tbl_employee;
use customer;
select * from student1;
/* cluases */
select
from
where
group by
having
order by
/* where */
select * from student1 where district like 'pune' and marks < 80;
select * from student1 where district like 'pune' or marks < 80;
select * from customer where exists (select * from orders where customer.custid=
orders.custid and custid = 5);
select * from customer where custid = any (select custid from orders where
productname = 'clothes');
select * from customer where custid = all (select custid from orders where
productname = 'clothes');
/* aggregate functions */
count()
sum()
min()
max()
avg()
round()
/*scaler functions */
len()
upper()
lower()
/* group by clause */
/* having clause */
/* order by clause */
/* constraints */
not null
default
check
/* not null */
insert into tblnotnull (id, name, address) values (1, 'shreya', 'Wai');
insert into tblnotnull ( name, address) values ( 'shreya', 'Wai');
insert into tblnotnull (id, address) values (1, 'Wai');
/* default constraint */
insert into center (id, name, center) values (1, 'sahil', 'pune');
insert into center (id, name) values (1, 'sahil');
insert into center (id, name, center) values (2, 'pooja', 'Thane');
insert into center (id, name) values (3, 'pratik');
/* check constraint */
/* sql keys */
primary key
unique key
alternate key
foreign key
composite key
super key
candidate key
/* primary key */
insert into tblstudent (studid, studname, address) values (11, 'viaan', 'KP');
insert into tblstudent (studid, studname, address) values (7, 'viaan', 'KP');
/* unique key */
insert into tblstudent1 (studid, studname, address, mobile, adharno) values (1,
'viaan', 'KP', 9090909090, 454323456789);
insert into tblstudent1 (studid, studname, address, mobile, adharno) values (2,
'viaan', 'KP', 8880909090, 134623456789);
insert into tblstudent1 (studid, studname, address, mobile) values (3, 'viaan',
'KP', 9090909088);
insert into tblstudent1 (studid, studname, address, adharno) values (4, 'viaan',
'KP', 954323456789);
insert into tblstudent1 (studid, studname, address, adharno) values (5, 'viaan',
'KP', 994323456789);
/* foreign key */
/* composite key */
/* sql joins */
1.INNER JOIN
2.OUTER JOIN
a.LEFT OUTER JOIN
b.RIGHT OUTER JOIN
c.FULL OUTER JOIN
3.CROSS JOIN
4.SELF JOIN
/* INNER JOIN */
/* cross join */
select * from orders cross join customer where custname like '%a';
select * from orders cross join customer where custname like '%s%';
/* self join */
/* top limit */
select * from student1;
/* auto increment */
for mysql AUTO_INCREMENT() for sql server IDENTITY(1st value, incrementing value)
/* index */
/* drop index */
/* stored procedure */
exec procedurename;
exec studentdata;
/* sql view */
/* drop view */