0% found this document useful (0 votes)
9 views

Lab 3

Uploaded by

danish mahajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lab 3

Uploaded by

danish mahajan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

step-1:Toseealldatabases.

Command —-> ‘showdatabases;’

Step-2:TocreateanewDatabase.
Command—-> ‘createdatabasedbms_name;’

Step-3:Openadatabase.
Command—-> ‘usedbms_name;’

Step-4:Creating table and show description of table in database.


Command—-> ‘createtabletable_name(data_fields);’
Datafields:example—>namevarchar(50),roll_noint(10),branchvarchar(5)
Step-5:Insertingdataindatabase.
Command—-> ‘insert into table_name values(data); ’
Command—->‘ insertintolab_record(data_fields)values(data);’
Command—->‘ insert into lab_record values(data1),(data2); ’
INSERTINTOactors(id,first_name,second_name,gender)VALUES((1,'Tom','Hanks','Male'),(2,
'Leonardo','DiCaprio','Male'),(3,'Scarlett','Johansson','Female'),(4,'Brad','Pitt','Male'),(5,'Jennifer',
'Lawrence', 'Female'),(6, 'Johnny', 'Depp', 'Male'),(7, 'Meryl', 'Streep', 'Female'),(8, 'Robert', 'Downey Jr.',
‘Male’),….);
INSERTINTOmovies(id,name,year,rankscore)VALUES(1,'ForrestGump',1994,8.8),(2,'Titanic',1997,
8.7),(3,'TheAvengers',2012,8.0),(4,'Inception',2010,8.8),(5,'TheDarkKnight',2008,9.0),…);
INSERTINTOdirectors(id, first_name, last_name) VALUES((1, 'Steven', 'Spielberg'),(2, 'James', 'Cameron'), (3,
'Christopher', ‘Nolan'),(4, 'Martin', 'Scorsese'),(5, 'Quentin', ‘Tarantino’),…..);
Step-6:Createtableforidofactors&movieswhereactor_id,movie_idisforeignkey.
TheFOREIGNKEYconstraintisusedtopreventactionsthatwoulddestroylinksbetweentables.
AFOREIGNKEYisafield(orcollectionoffields)inonetable,thatreferstothePRIMARYKEYin another
table.
createtableactors_movies(actors_idint,movies_idint,primarykey(actors_id,movies_id),
foreignkey(actors_id)referencesactors(id),foreignkey(movies_id)referencesmovies(id));

Step-7:Toseealltablesindatabase.

Step-8: The ORDER BY keyword is used to sort the result-set in ascending or descending
order.The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
Command —-> ‘SELECTcolumn1,column2,...
FROMtable_name
ORDERBYcolumn1,column2,...ASC|DESC;’
TheLIMITclauseisusedtospecifythenumberofrecordstoreturn.TheLIMITclauseisusefulon large
tables with thousands of records. Returning a large number of records can impact performance.
Command —-> ‘SELECTcolumn_name(s)
FROMtable_name
WHERE condition
LIMIT number; ’
Step9: TheOFFSET keywordhelp to startlimit afterthat primary key.

Step-10:TheSELECTDISTINCTstatementisusedtoreturnonlydistinct(different)values.
Command —-> ‘SELECTDISTINCTCountryFROMCustomers;’
Step-11:Thesymbol<>inMySQLissameasnotequaltooperator(!=).

Step-12:ThenotinMySQLisusedtooppositeofthatcommand.

Step-13:TheBETWEENoperatorselectsvalueswithinagivenrange.Thevaluescanbe
numbers,text,ordates.TheBETWEENoperatorisinclusive:beginandendvaluesareincluded.

You might also like