Вы находитесь на странице: 1из 3

Here we will learn about Mysql.... i have already installed it...... we will see various operation abt it....

see my password------>is database throgh which we access....u must give the right pa ssword otherwise it will shut.. ==================== 1>everything start with databases; so we will first the databases which available in our mysql ===>use--->show databases;(chose the ; mark must) see i hv so many databases...... 2>if you r using first then there might be no databases; then we need to create databases; see how to create... create database sumit;//creating database with name sumit //so the name of database i hv created is sumit.... again use the show databases;(must use 's' at last here) see sumit database created; 3>now for using the database which you want to use write ------->use sumit;(i.e use [databasename] use database sumit;is wrong se e so now databse hv been changed 4>now if we want to see how many tables are there in my database then use.. show tables; NOTE--here for paste ctrl+v doesn't work u hv to right click then click on paste .. we hv not created any tables that why so emptyset.. 5>let create the tables; =====>create table [tablename] create table SumitTable(===>create table [tablename] must use this P_Id int,====>rem first propertyname then their type like here P_Id (propert yname) than type(int) same for all LastName varchar(255),=========>varchar(255)...it;s help us b,coz it will only u se that amt of space which it needed //not all like char(255),---even char is ok but it will waste the space which u hv not used FirstName varchar(255),========>rem to use comma(,)--->only LAST PROPERTY SUD NO T HAVE COMMA Address varchar(255),===>same rule follow Sid int,---------------->it does not need varchar..only string(here varchar) nee d thay City varchar(255)--->Last property so it sud not have comma(,) );====>must end with semi-colon(;) and property sud be written b/w "(" and ")"..... 6>now use again show tables; Note===>we have made table with name SumitTable but it is there sumittable(not a problem) 7>for seeing the configuration of table use describe sumittable;===========>i.e describe [name of table]

8>for inserting values in the tables use //you can write INSERT and VALUES in lower case also...not a problem...imp VALU ES must hv "S" in end not value // using "sumit" is wrong use 'sumit' for any string(varchar here) use '----' //u must write in the sequence you made the table INSERT into sumittable VALUES(1,'mishra','sumit','bnjhacolony',111,'madhubani'); //insert more values now we have inserted our values 9>for seeing our record use ----->select * from sumittable;//"*" is used for selecting all ------>select LastName,firstName FROM sumittable;//if you want to select only th ose you want must use FROM Note:--see here we use firstName which make difference even we used FirstName in table; ------>if there is duplicate record than how to use distinct only one record,... let seee i hv inserted one record thrice use select * from sumittable; after inserting duplicate record now if we need to choose only distinct value(i.e only one then use) 10> Select DISTINCT LastName from sumittable; thus see only distinct Lastname has been chooosed.. select * from sumittable where LastName='mishra';//so here "from" and "where" i s important rem that select * from sumittable where sid=111;//so for int (sid) also use b/w '---' //no it's not giving any error so you can choose whatever you like select * from sumittable where Firstname='sumit' and LastName='mishra'; //thus and is used to make more filter in searching so rem "and" is used when we hv to search for two distinct properties in one rec ord here for ex----firstname and lastname for only one person select * from sumittable where Firstname='sumit' or FirstName='amit'; //or is used to search for only one property....don't use FirstName and lastName //u can use also....not any problem OR means here all satisfing the any one condition AND means here only those satisfying both condition 11> if you want to get record in sorted order then use; select * from sumittable ORDER BY LastName ;//rem to give one space b/w "order" and "by"---->this is in ascending select * from sumittable ORDER BY LastName DESC;//in descending //see when we remove space between order and by there is error 12>fordeleting the record use Delete from sumittable where lastname='mishra' and firstname='sumit';//here imp

to use where +and see those with sumit as firstname and mishra as a last name hv been deleted; //for deleting all record use Delete * from sumittable;//i am not gonna use that now... Delete from sumittable;//is also same as delete * from sumittable so remember that without using where all will be deleted //there is lil differnce b/w DELETE AND TRUNCATE DELETE----->one by one----->syntax-------->delete from sumittable TRUNCATE---->all at once-------->syntax-------->Truncate table sumittable;

Вам также может понравиться