6 Aug 2017

What is sql and sql commands with syntax


Q1. How to create database 

Ans. create database college 

Q2. How to Use database

Ans. use College 

Q3. how to create Table 
syntax-
create table st  
  
Rno int, 
 Name varchar(20), 
 Fees float 
)

Q.How to Alter Table 

(Add new field course) 
syntax-  
alter table st add course char(10)
Q.How to Alter Table 

(Delete field course) 
syntax-  
alter table st drop column course 
Q.How To modify datatype 
syntax-  
alter table st  
alter column address varchar(20),

Q.How to delete table 
syntax-  
              drop table st 

Q.How TO Rename Field 
syntax-   
                 sp_rename 'st.rno','id' 

Q.How TO Rename Table 
syntax-  
                  sp_rename st,stud 

Q.How To Rename Database 
syntax-  
                  sp_renamedb college,niit 

Q.HOW To Apply Primary key Constraint time of table creation

syntax-
create table student 
  
rno int primary key, 
name char(30), 
fees float  
)  
Q.Another way to create a Primary Key 

syntax-
create table student  
(  
rno int, 
 name char(30),  
fees float,  
constraint pk primary key(rno)  
Q.Primary key with multiple columns is a table-level constraint 

syntax-
create table student1 
 (  
rno int, 
 name char(30), 
 fees float, 
constraint pk1 primary key(rno,name)  
Q.Add constraint primary key with the help of alter table 

->First condition—field should be not null 
syntax-  
        alter table emp12 add constraint pk5 primary key(eid) 

Q.How to drop a constraint 

        syntax-
      alter table emp12 drop constraint pk5 

Q.How to create Foreign Key 
syntax-
create table performance 
 (  
eid int, 
 increment int, 
 constraint fk foreign key (eid) references emp12(eid) 
 ) 

Q.How To create Unique Constraint 

syntax-
create table exam  
 
rno int not null unique, 
 name varchar (20)unique  
Q.CHECK CONSTRAINT 

syntax-
create table emp  
 
eid int, 
ename char(30), 
ms char(1) check(ms='s' or ms='m'), salary float 
 
Q.Default Constraint 
syntax-
create table emp  
 
eid int, 
 ename char(30), 
salary float default 1000 
 

Q.NOT NULL Constraint .

syntax-
create table emp  
 
eid int, 
ename char(30) not null, 
salary float  

Q.AUTO INCREMENT 

syntax-
create table emp  
 
eid int identity(100,1)primary key, 
 ename char(30) not null,  
salary float  
Q.HOW to Insert Data 

syntax-
insert into emp values(101,'amit',40000) 

Q.Another way to Insert data 

syntax-
insert into emp(eid,name,salary) values(102,'rakhi',50000) 

Q.Update Record with single field 

syntax-
update emp set name='reena' where eid=2 

Q.Update Record with multiple field 

syntax-
update emp set name='reena',salary=5000 where eid=2 

Q.Delete single record 
syntax-
delete emp where eid=2 

Q.Delete All Record 
syntax-
Delete emp 

Q.Select all field and Record 
syntax-
select * from emp 

Q.select perticular field 

syntax-
select eid,name from emp 

Q.select perticular record 

syntax-
select * from emp where ename=102 

Q. select a particular record with a relational operator 

syntax-
select * from emp where salary>5000 

Q. select a particular record with the logical operator 

syntax-
->select * from emp where eid=102 and ename='rakhi'  

-> select * from emp where eid=102 or ename='rakhi'  

-> select * from emp where not ename='rakhi' 

Q.Select particular record with distinct keyword 

syntax-
select distinct city from emp 

Q.Use between in Select statement 

syntax-
select * from emp where salary between 4000 and 5000 

Q.In clause in select statement 

syntax-
select * from emp where grade in('A','B')

Like clause in the select statement 
->%---more 
->_--single 

syntax-
select * from emp where name like 'r%a_' 
Q.USE ORDER BY Clause 

-> increase Order 
syntax-

select * from emp order by ename  

 select * from emp order by ename asc 

->Decreasing 
syntax-
select * from emp order by ename desc 

No comments:
Write comments

Contact Form

Name

Email *

Message *

© 2014 Rock Programmer . Designed by Bloggertheme9
Powered by Rock Programmer.