SQL 2000 practice Accumulation

Source: Internet
Author: User

Code:
1. If possible, conditional judgment is required to avoid unnecessary errors.

Use hferpdb -- select database

Select * From hr_person -- it is best to specify fields when querying data, which improves efficiency.

Select role name, NAM, sex, age, identityno, workdate, duty, educationlevel, tel, telbak from hr_person

Select * into hr_personbackup from hr_person -- copies the table and is only used for testing.

Update hr_person set Tel = B. Phone, telbak = B. Duan from hr_person, phone B
Where hr_person.nam = B. Nam -- extract data from another table to update the current table

Drop table hr_personbackup -- delete the entire table

Select count (NAM) 'name displayed in this column 'from phone -- count the number of fields

 

Delete from hr_person where Tel is null -- delete, it is best to add a condition

Select top 0 * from people -- used to check the field name

Delete from people where Xingming in (select Nam from hr_personbackup group by NAM)
-- The condition can be a dataset, not necessarily a table.

Insert into phone (NAM) Select Xingming from people P where P. Xingming is not null
-- Insert a field into the target table

-- Inserts data from one table into the specified column of another table
Insert into hr_person (partition name, NAM, sex, identityno, workdate, duty, educationlevel, lastopdate, createdate, issocialsec, id_person)
Select bumen, Xingming, sex1, sfz, worktime, job2, xueli, getdate (), getdate (), 0, Id2 from people where Id2 is not null

-- Truncate the date of birth of the ID card
Select substring (identityno, 7,8) from hr_personbackup

-- Convert ID card to date of birth
Select cast (substring (identityno, 7,8) as datetime) from hr_personbackup

-- Get the age of the ID card to the present time, but generally it is the design age field = current time minus current time
Select datediff (year, substring (identityno, 7,8), getdate () from hr_personbackup

-- Cast is used to convert the field format, but it must be different from the format of the target field
Update hr_person set Birthday = cast (substring (identityno, 7,8) as datetime) from hr_person

 

-- Search for the same record
Select Nam from hr_person group by Nam having count (NAM)> 1

 

Not complete...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.