Some of the basic commands in Oracle

Source: Internet
Author: User

--New UserCreate UserExample identified by 123456;--Delete UserDrop Userexample;--Lock UserAlter Userexample account lock;--Unlocking UsersAlter Userexample account unlock;--Modify User PasswordAlter UserExample identified by 654321;--grant permissions, RolesGrantConnect toExample--roleGrantResource toexample;GrantDba toexample;Grant Create Table  toExample--New Table PermissionsGrant Create View  toExample--New View Permissions--revoke permissions, RolesRevoke Create View  fromexample;RevokeConnect fromexample;--New Table SpaceCreatetablespace exmpdatafile'G:\aaa\HP.DBF'size 5mautoextend on Next2mmaxsize Unlimited;--Create a user and set the default TablespaceCreate UserAAA identified by 123456defaulttablespace BBB;--Modify the user default tablespace in case the user creates itAlter UserExampledefaulttablespace aaa;--modify quotas for a table spaceAlter UserExample Quota 10m onAAA--New TableCreate TableEMP (empno Number, EmpNamevarchar2(Ten), Empsexvarchar2(3));--Modify TableAlter TableEMP Modify Empsexvarchar2(Ten) not NULL;--Modify Field LengthAlter TableEMP Modify Empsexdefault 'male';--Fix the field default valueAlter TableEmpDrop columnEmpsex;--Delete a fieldAlter TableEmpAdd(Empsexvarchar2(3));--Add FieldAlter TableEMP RenamecolumnEmpsex toGender--Rename field nameRename EMP toEMP1;--Renaming a table--Delete a tableDrop TableEMP;--Set Primary KeyAlter TableEMPAdd constraintPk_empnoPrimary Key(empno);--set foreign keysCreate TableBm--Create a new Department tableBmno Number, Bmnamevarchar2( -));Alter TableBMAdd constraintPk_bmnoPrimary Key(BMNO);Alter TableEmpAdd(Bmno Number);--Add a Department number field to the Employee tableAlter TableEmp--set Bmno as foreign keyAdd constraintfk_empForeign Key(Bmno)ReferencesBM (BMNO);--This field is set to the foreign key if the primary key in another table--Add a Check constraintAlter TableEMPAdd constraintC_sexCheck(Empsexinch('male','female'));--Add a UNIQUE constraintAlter TableEMPAdd constraintU_nameUnique(empname);--Create a sequenceCreatesequence Seq_empmaxvalue999Start with 1Increment by 1Cache -;--using sequencesSelectSeq_emp.nextval fromDual--Next Sequence valueSelectSeq_emp.currval fromDual--Current Sequence valueInsert  intoEMPValues(Seq_emp.nextval,'Jiali','male', A);--Delete a sequenceDropsequence seq_emp;--Add a recordInsert  intoEMP (EMPNO,EMPNAME,EMPSEX,BMNO)Values(Seq_emp.nextval,'Cong','female', A);Insert  intoEMPValues(Seq_emp.nextval,'Fei','female', A);--Deleting RecordsDelete  fromEMPwhereEmpno=8;--Modify Record (update)UpdateEmpSetEmpName='Weiwei' whereEmpno=1;

Some of the basic commands in Oracle

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.