Untitled
unknown
plain_text
2 years ago
4.0 kB
26
Indexable
find out database
command=> show databases;
create database:
syntax=> create database database_name;
create database second;
select working database
syntax:-use database_name;
=>use second
----------------------------------------------------------
create table:
syntax:
create table table_name(
column1 datatype,
column2 datatype,
column3 datatype,
-
column3 datatype
);
exa:- create table Student(
rno int,
name varchar(20),
address varchar(20),
marks int,
gender char(1));
checking table:
show tables_name;
=> show Student;
for showing table structure:
syntax:desc tablename;
exa :-desc Student;
--------------------------------------------------------------------------
insrt data into table:
seuence is manadatory.
number of column =number of values
1- insert into tablename values(value1,value2,-----valueN);
exa:- insert into Student values(1,'nikki','pune',56,'male');
----------------------------
--sequence is manadory for column we given in insert stament
count of column specify into insert =number of values
no value for any column.
2.- insert into Tablename(column1,column2-----columnN) values(value1,value2,-----valueN);
ex:- insert into Student(rno,name,marks,gender) values(2,'nikita',70,'F');
--------------------------
multiple value insert at one time
syntax:- insert into tablename values(value1,value2,-----valueN),(value1,value2,-----valueN)-----(n);
exam:- insert into Student values(3,'ram','satara',67,'m'),
(4,'anita','nagpur',89,'F'),
(5,'jashu','nagpur',90,'M');
-----------------------------------------------------------------------------------------------------
fetch all record from tables:-
syntax:-
selct * from tablename;
exam:-select * from Student;
fetch select column from table;
ex;- select name,marks from Student;
---------------------------------------------------------------------------------------
Contraints in sql:
contraints is use for to specify rules for the data in table.
1. NOT NULL:-ensure that the column cannot have a null values:
2.UNIQUE:-ensure that all values in a column are differents.
3.CHECK:-Ensures that the values in a columns satisfies a given specific condition.
4.DEFAULT:-set a default value if value is not specified for a column.
5.PRIMARY KEY:-ensure that the values of column is NOT NULL and UNIQUE.
syntax:-
create table table_name(
column1 datatype contraint,
column2 datatype contraint,
-
-
columnN datatype contraint
);
--------------------------------------------------------------------------------------------
Drop command:-
for database:
is used for delete the existing sql database.
syntax:- drop database Database_name
example:- drop database demo1;
for table:
drop table command is used for the table structure delete from database.
syntax:- drop table table_name
example:- drop table student;
-----------------------------------------------------------------------------
truncate command:
is used for delete the data from tables.
it is used for empty table.
syntax:-tuncate table tablename;
exa;- truncate table customer;
-------------------------------------------------------------------------------------------
Difference between drop and trucate:
Drop :-1.Drop command is use for remove table defination /table structure from database.
2. table does not exist in databse.
Truncate:-1.truncate command is used for delete all rows from tables.structure remain same.
2.table is exist in databse.show empty table.
----------------------------------------------------------------------------------------
Assignment:-
Create Customer table.
custid primary key,
name unique,
address not null
age age>18
gmail abc@g.com
insert minimum 10 records
-Editor is loading...
Leave a Comment