Measure the test taker's understanding about the operations in a table in El.
Goal: Learn about table creation and modification and related operations.
Preface:
Oracle: The table is created in the user solution, rather than directly belongs to the database!
Sqlserver: The table directly belongs to the database!
- 1. Create a table:
- Keywords:Create
- Create TableTable Name (
- Column name 1, data type, other attributes,
- Column name 2, data type, other attributes,
- ...
- Other attributes of the last data type
- );
- Note: in oracle, when creating constraints, like SQL Server, they are also directly written.Primary Key,Check(Xxx), and so on, but the only difference is
- Foreign key constraints have some changes:
- Eg: typeIdIntCostraint (typeId) refereces TypeInfo (typeId );
- Instead:
- Eg: typeIdInt Foreign Key(TypeId) refereces TypeInfo (typeId );-- (Some of them are written in this way, but I have never written it !)
- 2. Table Modification
- A) add a column:
- Alter TableTable NameAddField Name Data Type attribute;
- B) Modify columns:
- Alter TableTable NameModifyColumn Name Data Type attribute;
- C) delete a column:
- Alter TableTable NameDrop ColumnColumn name;
- D) modify the table name:
- Alter TableRenameToNew table name;
- 3. Create a new table through an existing table (and enter existing data into the new table)
- Create TableNew table nameAs SelectColumn name 1, column name 2 ,....FromOld table name;
- 4. Table space operations:
- A) create a tablespace:
- CreateTablespace name datafile ='Tablespace path (the file name often ends with dbf )' SizeXXM;
- Note:SizeThe unit of the following number is not MB, but M, eg:Size50 m;
- B) create a temporary tablespace:
- Create TemporaryTablespace temporary tablespace name tempFile ='Path (same as the file name )' SizeXxM;
- C) Specify the tablespace for the user.
- Alter UserUser NameDefaultTablespace name;
- D) specify a tablespace for the table (which must be specified during creation ):
- Create TableXXX (
- XXX XX XXX
- ) Tablespace name;
- E) delete a tablespace:
- 1) only perform logical deletion, that is, delete the structure, but the physical file still exists:
- DropTablespace name incuding contents;
- 2) Delete All:
- Drop TableName: including contentsAndDatafile;
- F) modify the tablespace size:
- Alter DatabaseDatafile ='Path (and file name) of the newly added data file )'Resize XXM;