--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