Uploaded by abid.khan1999bd

l1

advertisement
To install mysql: (You will have it installed in lab computer; in case you want to install it in your personal
computer)
●
May have to install, depending on the computer setting:
●
Go to:
●
Then select:
○
○
visual studio x64 redistributable 2019 and over.
https://dev.mysql.com/downloads/mysql/
○
●
Then, select “NO THANKS“
○
●
Now, “mysql-8.1.0-winx64“ will be downloaded.
●
Select next in this window:
○
●
Then Select “developer default“ setting.
●
Select all default settings.
●
Give root password.
●
Continue with “next“s, with selecting all default settings.
●
Now mysql installation is done.
Creating table:
This is a sample table, named ‘student table’, we are going to create:
student_id
name
major
100
jkl
Computer
science
101
mno
Business
102
pqr
Pharmacy
103
stv
Business
●
Go to “mysql command line client” from start window.
●
It will ask for the root password. Give, and enter.
●
In terminal write:
○
create database cdf;
■
[here, cdf is the database name].
■
[Use a different database name next time, as the table is already created in this database].
■
[if it's right, it will show “Query OK”]
■
■
○
use cdf;
■
[it is to use any particular database you are going to use for your coming inputs].
■
○
select database ();
■
[now we are going to create a table in this particular database].
○
○
create table student (
■
student_id INT,
■
name varchar(20),
■
major varchar(20),
■
primary key (student_id)
■
);
●
Here," student" is the table name.
●
INT: a number that is not a fraction; a whole number.
●
Varchar: Can contain letters, numbers, and special characters.
●
Enter. [if it's right, it will show “Query OK”].
○
20 is the character length.
●
○
show tables;
■
It will show all existing tables in the created database.
■
○
describe student;
■
It will show the details of the student table.
■
Alter table:
●
We are going to add gpa column to the existing student table.
●
student_id
name
major
gpa
100
jkl
Computer
science
3.56
101
mno
Business
3.04
102
pqr
Pharmacy
3.25
103
stv
Business
3.33
alter table student add gpa decimal(3,2);
○ Decimal numbers are not whole numbers.
○ 3 is total number of digits.
○ 2 is after point, how many digis you want to see.
○
●
describe student;
○
Delete table:
●
drop table student;
○
●
show tables;
○
●
describe student;
○
Download