Two days ago we learned some of the most basic database-related knowledge, starting today, we have shallow to deep learning database knowledge, for our future work to lay a solid foundation, for you Yimeimei can see clearly I want to express the meaning, From today, we also use the image format to each statement before and after the implementation of the data what changes have come up (blog Park just opened 5 days, inside a lot of things are not too familiar with, hope understanding), so that we more at a glance, nonsense not much to say, below the beginning of our study today.
1. First we create a data table, insert some simulation data, so that we can save a lot of time to create data, so that we can fully think and learn SQL
--Create company staff information table
use Study create table company staff Information Sheet (employee number int , staff name varchar (50 ), staff gender varchar (20 int staff salary int , home address varchar (200
--inserting simulation data into the company employee information sheet just createdInsert intoCompany staff Information Sheet (employee number, employee name, gender, employee age, employee salary, home address)Values(1,'Zhang San','male',' at',' the','Fengtai District, Peking City')Insert intoCompany staff Information Sheet (employee number, employee name, gender, employee age, employee salary, home address)Values(2,'John Doe','female',' +','4000','Chaoyang District, Beijing')Insert intoCompany staff Information Sheet (employee number, employee name, gender, employee age, employee salary, home address)Values(3,'Harry','male',' -','2500','Haidian District, Beijing')Insert intoCompany staff Information Sheet (employee number, employee name, gender, employee age, employee salary, home address)Values(4,'Zhao Liu','female',' -','3200','Xicheng District, Beijing')Insert intoCompany staff Information Sheet (employee number, employee name, gender, employee age, employee salary, home address)Values(5,'Sun VII','male',' at','3500','Beijing Changping District')
2. Consult the company staff information sheet to determine if the insert was successful, such as:
It's still so easy, right, well, with the data source, we'll be able to devote all our energies to the SQL statement.
3. Then we will follow the previous study of SQL query, insert, UPDATE, delete all through the table this data to intuitive operation:
--First we look at all staff information in this table that is more than 3000 of the staff salary, such as:
Select*fromwhere staff salary >
The staff number 2, 4, 5 is to meet our query statement staff salary >3000 all staff information:
--then we would like to inquire about the company staff Information table gender is female and staff salary >3000 information, how should we inquire? Such as:
Select * from where staff gender =' women ' and staff salaries > Here and we can understand and mean, there is also a or is or meaning, we will explain later
the staff number 2, 4 is to meet our query statement company staff information gender for women and staff salary >3000 all personnel information
-- How to change the salary of the employee named Zhang San to 10000
Updateset Clerk Salary ='10000'where clerk name =' Zhang San '
Employee pay in the middle circle has been changed to 10000
--Below we re-insert a piece of data, the data information is numbered 8, the employee's name is Xiao Chen, gender is male, age is 25, salary is 7000, home address is Beijing Changping District
Insert into company staff information sheet (employee number, employee name, gender, employee age, employee salary, home address)values(8,' Xiao Chen ',' male ',7000,' Beijing Changping District ' )
Post-insert results such as:
--Let's delete this message with the employee's name Xiao Chen
Deletefromwhere clerk name =' Xiao Chen '
After deletion, the results are as follows:
Well, the above is our first two days of study content of a small review or summary, tomorrow we continue to study.
Third day of SQL Server 2008 Learning