CRUD Flashcards
Syntax for creating a database
Create database DATABASENAME;
Is the mysql command case sensitive?
No
TRUE OR FALSE:
The database name must follow the rules in naming variable
TRUE
Is the semicolon a requirement in database?
Yes
Display all the database in my sql
Show databases;
Deleting the database
DROP database DATABASENAME;
Creating a table
create table tablename(
field1 datatype1
field2 datatype2
field3 datatype3);
Adding field to the table
alter TABLE TABLENAME add FIELD DATATYPE;
Changing the data type or fieldname of the table
alter TABLE TABLENAME change OLDFIELD NEWFIELD DATATYPE;
Setting a primary key of the table
alter table TABLENAME add primary key(FIELDNAME);
Deleting a field
alter table TABLENAME drop FIELDNAME;
SHOWING ALL TABLES IN THE DATABASE
SHOW TABLES;
Renaming table
alter table ORIG_NAME rename NEW_NAME;
Adding Record to Table
insert into TABLENAME values(VALUE1, VALUE2, VALUE3, ….);
Inserting record to table example
insert into STUDENT values(‘101’,’Cris’,’Female’,15,5500)
Used to view the record of the tables
select * from TABLENAME;
column modifier is used to display leading zeros of a number based on the display width.
ZeroFill
column modifier automatically increases the value of a column by adding 1 to the current maximum value.
Autoincrement
How to use ZeroFill?
create table student( student_no varchar(20), firstname varchar(20),age Tinyint(4) Zerofill);