CRUD Flashcards

(49 cards)

1
Q

Syntax for creating a database

A

Create database DATABASENAME;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Is the mysql command case sensitive?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

TRUE OR FALSE:
The database name must follow the rules in naming variable

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is the semicolon a requirement in database?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Display all the database in my sql

A

Show databases;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Deleting the database

A

DROP database DATABASENAME;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Creating a table

A

create table tablename(
field1 datatype1
field2 datatype2
field3 datatype3);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Adding field to the table

A

alter TABLE TABLENAME add FIELD DATATYPE;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Changing the data type or fieldname of the table

A

alter TABLE TABLENAME change OLDFIELD NEWFIELD DATATYPE;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Setting a primary key of the table

A

alter table TABLENAME add primary key(FIELDNAME);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Deleting a field

A

alter table TABLENAME drop FIELDNAME;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

SHOWING ALL TABLES IN THE DATABASE

A

SHOW TABLES;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Renaming table

A

alter table ORIG_NAME rename NEW_NAME;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Adding Record to Table

A

insert into TABLENAME values(VALUE1, VALUE2, VALUE3, ….);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Inserting record to table example

A

insert into STUDENT values(‘101’,’Cris’,’Female’,15,5500)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Used to view the record of the tables

A

select * from TABLENAME;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

column modifier is used to display leading zeros of a number based on the display width.

A

ZeroFill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

column modifier automatically increases the value of a column by adding 1 to the current maximum value.

A

Autoincrement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to use ZeroFill?

A

create table student( student_no varchar(20), firstname varchar(20),age Tinyint(4) Zerofill);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Example on how to use AUTOINCREMENT?

A

create table student(student_no INT PRIMARY KEY AUTO_INCREMENT, firstname varchar(20));

21
Q

Editing Record

A

UPDATE tablename SET fieldname = value where fieldname = criteria

22
Q

What is being done?

UPDATE EMPLOYEE SET FirstName = ‘Crista’ where Emp_no = ‘101’

A

The FirstName of Emp_no 101 will be set to Crista

23
Q

What will happen?

UPDATE tbemployee SET FirstName = ‘Crista’

A

This command will change the first name of all record to Crista

24
Q

What will happen?

UPDATE tbemployee SET age = age + 2

A

All recorded will be updated by adding 2 to the age

25
What will happen? UPDATE EMPLOYEE SET salary = salary + 500 where gender = ‘female’
All female employee will be updated by adding 500 to the salary.
26
What will happen? UPDATE EMPLOYEE SET age = 19, salary = 6100 where emp_no = ‘102’;
The record of employee who have a employee number of 102 will be updated. The salary will be set to 6100 and age to 19
27
Deleting Record
Delete from TABLENAME where CONDITION;
28
What will happen? Delete from tbstudent where sn = ‘102 ’;
This command will delete an student who have a student number of 102
29
What will happen? Delete from tbstudent where firstname =‘Karen’ and lastname =‘Lagasca’;
This command will delete an student who have a first name of Karen and last name of Lagasca
30
What will happen? Delete from tbstudent where firstname like ‘m%’
This command will delete an student who have first name that start with letter m
31
- A statement used to select data from a database. - The result is stored in a result table called the **result-set**
SELECT
32
How to select ALL FIELDS of a table?
SELECT * FROM table_name;
33
Use select command with selected field
SELECT column_name, column_name FROM table_name;
34
- used to sort the result-set by one or more columns. - sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.
SQL ORDER BY KEYWORD
35
SQL ORDER BY KEYWORD SYNTAX
SELECT column_name,column_name FROM table_name ORDER BY column_name,column_name ASC/DESC
36
What is being done? SELECT * from EMPLOYEE order by LASTNAME ASC
The records will be ordered alphabetically by last name in ascending order
37
SELECT * from EMPLOYEE order by DEPT
This will display all the record that sorted by department in ascending order
38
- clause used to filter records - used to extract only those records that fulfill a specified criterion.
THE SQL WHERE CLAUSE BY KEYWORD
39
How to display all the records that have a position of manager in a table named employee?
SELECT * FROM employee WHERE position = ‘Manager’
40
How to display all the record that have a department of ACC in employee table?
SELECT * FROM employee WHERE dept = ‘ACC’
41
- can be used in SQL command especially in number - <, >,<=, >=, =, <>
Relational Operator
42
Display All the record from employee table that have a salary greater than 10000
select * from employee where salary > 10000;
43
- It is used to select values within a range. - Selects values within a range. The values can be numbers, text, or dates.
BETWEEN KEYWORD
44
SYNTAX FOR BETWEEN KEYWORD
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
45
What will happen? select * from EMPLOYEE where AGE BETWEEN 20 AND 25;
This will display all the record that the age is between 20 and 25. Remember that 20 & 25 are included
46
Display all the record from EMPLOYEE table that the FIRSTNAME start from C to G only and not the H
select * from EMPLOYEE where FIRSTNAME BETWEEN ‘C’ AND ‘H’;
47
It allows you to specify multiple values in a WHERE clause.
IN KEYWORD
48
IN KEYWORD SYNTAX
SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);
49
WHAT WILL HAPPEN? select * from EMPLOYEE where age in (18, 25)
This will display all the record that the age is 18 or 25