CS311 Database Management system Lecture 6 CS311 Database Management system Somchai Thangsathityangkul
SQL IBM Sequel language developed as part of System R project at the IBM San Jose Research Laboratory Renamed Structured Query Language (SQL) Language for database definition, manipulation, and control International standard Oracle SQL Server DB2 mySQL
What do we need for mySQL ? Wamp : www.wampserver.com/en/index.php After we install wampserver, we will have apache , php , MySQL in our PC.
Install wamp server
Type directory to install
Press Enter
Create new database Now , we can create any new database for our project. Create database databasename; Suppose we want to create cs311 db. Type command : Create database cs311; Type command : Show databases ; this will show all databases we have Type command : use cs311 ; this will change current database to cs311
Command to show all Databases. Default Databases.
Command to create a Database. Database name cs311 .
Must select database first. Database name does not exist. Select database that we need.
Create Table Create Table table_name ( column_name data type , ………. , constraints ….. ) ;
Create table mytable ( my_id int auto_increment primary key , my_fname varchar(20) not null, my_address tinytext , my_birthday date ) ;
Create table my_friend ( friend_id int auto_increment primary key, friend_fn varchar(20) not null, my_id int not null, foreign key ( my_id ) references mytable ( my_id ) );
Show all tables in database Table mytable after created
There are two tables here. Only one table left after drop table. Drop table command Drop table is a command to delete a table that we do not use it anymore. Lets try to drop parent table by type command : drop table parent ; There are two tables here. Only one table left after drop table.