Database Queries Medina
Database Queries Medina
EmployeeNumber int
Name varchar 15
Salary smallmoney
Address varchar 20
1. INSERT INTO…VALUES
2. INSERT INTO…SELECT
INSERT INTO…VALUES – options needs the column list and all
the columns in the correct order.
Syntax:
INSERT INTO TableName VALUES
(‘char_attrib_val’,’num_attrib_val’)
Where:
char_attrib_val – short term for character attribute value.
num_attrib_val – is a short term for numeric attribute
value.
Example:
insert into Name1 values (‘Juan Cruz’); //then press !execute icon
Note: type this command after the inserting data to the table:
select * from Name1 (Name1 is the name of the table)
Example2. Input values into the Emplyee1 table, with the following
data:
or we use:
insert into Employee1 (Name, Address, EmployeeNumber,Salary)
values (‘Juan Tamad’, ‘imus cavite’, 001, 20500);
results:
result:
select * from Employee1 ;
result:
SQL UPDATE Command
•Is used to set or change data values in a table. We usually change
or set data in more than one row.
Syntax:
UPDATE tablename SET fieldname1, fieldname2,
fieldname3…..
update Employee1 Set Salary = 0;
select * from Employee1 ;
result:
update Employee1 Set Salary = 25000 where
result:
update Employee1 Set Salary = 12500
where EmployeeNmber = 4808;
select * from Employee1;
result:
SQL ALTER TABLE Command
- Command when we add, modify(change), and delete columns in a
table`s definition. This command belong to the SQL`s DLL (Data Definition
Language) group of commands, because it is used in changing the definition table.
Example:
alter table Employee1 add Position
varchar(20);
select * from Employee1 ;
result:
Changing a Column`s Data Type
- We are allowed to change the data type of an existing
column, provided that the new column data type can
accommodate the existing data. Meaning, that the new data
type is bigger or larger than the older one.
Syntax: alter table tablename
alter column columnname newdatatype
From: To:
alter table Employee1
alter column Name varchar(50)
result:
Deleting a Column
Syntax: alter table tablename
drop column columnname
Example:
alter table Employee1
drop column Gender;
From :
or
To:
Example2: Delete all employees whose salary is greater than
20,000 that can be found in the Employee1 table.
From:
From:
To:
Creating Comment
- Adding a comments in SQL statement is simple and
easy.
1. – dashes
2. /* … */
Example:
Select Command
- A command used to retrieve the data from a database.
Result:
Select Application With Columns Specified
Result:
Example2:
Syntax: select * from Employee1 where
EmployeeNmber = 1234
or Salary >= 20000;
result:
Thank you!!!