0% found this document useful (0 votes)
15 views1 page

SQL Commands Create and Insert

This document provides a guide on basic SQL commands for managing databases using XAMPP. It includes instructions for connecting to a MySQL server, showing databases and tables, creating databases and tables, inserting records, and altering existing tables. Sample commands are provided for each operation to illustrate their usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

SQL Commands Create and Insert

This document provides a guide on basic SQL commands for managing databases using XAMPP. It includes instructions for connecting to a MySQL server, showing databases and tables, creating databases and tables, inserting records, and altering existing tables. Sample commands are provided for each operation to illustrate their usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL COMMANDS

Go to xampp directory
Cd C:\xampp\mysql\bin
Connect to mysql server
Mysql -u root -p
• SHOW
show databases; // show all available database
use [database_name] //to deploy the desired database
show tables; // show available table within a selected database
• CREATE
create database [database_name]; // generate database
create table [table_name] ([field_name1] [data_type1], [field_name2] [data_type2],
[field_name3] [data_type3]); //generate a table with initialized column/field name
Sample:
Create table student_tbl (stud_id int unsigned auto_increment not null, stud_fname varchar(255) not
null, stud_lname varchar(255) not null, primary key(stud_id));
• INSERT
insert into [table_name] ([field_name1], [field_name2],[field_name3],…) values
([val1],[val2],[val3],…); // the insert value for each field, [field_name] & [val] should be aligned
to each other otherwise it will have error
insert into [table_name] values ([val1],[val2],[val3],…); // [val] should be aligned to the [field_name]
otherwise it will have error
insert into [table_name] values (‘ ‘,[val1],[val2],[val3],…); //auto increment for primary key
Sample:
Insert single record:
Insert into stud_tbl (stud_id, stud_fname, stud_lname) values(‘ ‘, ‘janessa’,’cruz);
Insert multiple records in one command:
Insert into stud_tbl (stud_id, stud_fname, stud_lname) values(‘ ‘, ‘janessa’,’cruz’), (‘ ‘, ‘juan’,’dela cruz’);

• ALTER
alter table table_name add column_name datatype; //add column into existing table
alter table table_name drop column column_name; //delete column into existing table
alter table table_name modify column column_name datatype; // To change the data type of a column
in a table

You might also like