MY SQL





In this we have used databases aditya & table named student have roll, name, and marks and address respectively.


SQL COMMANDS (BASICS)

  1.       To show databases  --  show databases;
  2.       To use databases  --  use aditya;
  3.       To create table  --  create table student(roll int, name char(20), marks float, address char(50));
  4.       To insert values into table  --  insert into student values(1,’Aditya’,70,‘New Delhi’);
  5.       To see table  --  select * from students;

      MORE SQL COMMANDS

       1)   Deletion Commands

·         To delete databases  --  drop/delete database aditya;
·         To delete table  --  drop/delete table students;
·         To delete under condition  --  delete from student where roll>2;
  
       2)   Creating tables
·         To create table with not null  --  create table student(roll int NOT NULL, name char(20), marks float, address char(50));
·         To create table with unique constraint  --  create table student(roll int UNIQUE, name char(20), marks float, address char(50));
·         To create table with primary key  --  create table student(roll int primary key, name char(20), marks float, address char(50));
·         To create table with default value  --  create table student(roll int default=’E1’, name char(20), marks float, address char(50));
·         To create with check Constraint  --  create table student(roll int check(roll>10), name char(20), marks float, address char(50));

       3)   Special commands
·         To display Name of those who has roll number >10  --  select name from student where roll>10;
·         To Display record of student whose roll no. lies b/w 2 to 20  --  select * from student where roll between 2 and 20;
·         To Display record of student whose roll no. lies 2 & 20  --  select * from student where(roll=2 and roll=20) ;
·         To Display record of student whose Address is not delhi  --  select * from student where address <>’delhi’;
·         To Display record of student order by roll no.  --  select * from student order by roll;
·         To Display record of student whose name contain NA  --  select * from student where name is like  ’%NA%’;
·         To Display record of student whose name contain 4 letters  --  select * from student where name is like  ’____’;
·         To update table  --  update student set roll=roll+50;
·         To do union  --  select * from student union select * from student1;
·         To add column read  --  alter student read char(20);

·         Count/frequency  of table  --  select count(*) from student;
·         Eliminate redundant data  --  select distinct name from student;



You can also check my channel

Comments

Post a Comment

Popular Posts