Chapter 8: Creating Tables and Enforcing Data Integrity Flashcards
What is a Base Table?
It’s a table which his definition and content remains in the SQL Server Instance, no matter if the SQL Server instance is restarded or shutdown.
What is a temporary table?
It’s a base table stored in the tempdb. His purpose is to use it while a session or until the user want.
What’s a table variable?
It’s a variable that can store data as a table does, but his existence is limited by the duration of the T SQL batch (this is, just during the execution of a T SQL batch).
What’s a view?
A View show data as a table does, but it’s defined by a query and if the view is queried, the query which build the view, it’s triggered.
What’s an index view?
Unlike a standard view, the index view is stored in the database as object. That’s because has a index in his structure.
What are the ways which T SQL allows you create a table?
The first one is used the statement CREATE TABLE, and the second one is using the SELECT INTO. The latter one creates a table through a query’s output.
What’s a database schema?
It’s a named container (like a namespace) which groups table and database objects.
What’s the difference between a database schema and a table schema?
A database schema is a container which groups database objects (like tables, functions, stored procedures, and so on), whereas a table schema is the structure of the table (like his colums and data types, and so on).
Mention the built-in database schemas that cannot be dropped.
- dbo: this schema is used when a database object is created for users which has the role of db_owner. Also, it’s the default schema if the schema is not specified.
- guest: it’s rarely used, but as his name says, it’s for guest users.
3 INFORMATION_SCHEMA: this schema has information about other schemas (REVIEW THIS ONE). - sys: it’s a SQL Server reserved schema, contains information about the current database.
Note: each database has each one of the mentioned schema (his own one).
Can a database schema be nested?
No, it can’t.
How a database schema can be created?
With this statement: CREATE SCHEMA [Schema Name] AUTHORIZATION [User who is owner of this Schema]. We need to know that a schema need to have a owner, just an owner. That owner can grant permission of this schema to other users.
Can a table which is in a schema, can be trasfered or moved to another schema?
Yes, it can. The statement ALTER SCHEMA [Destination Schema] TRANSFER [Source Schema].[Table Name]. If there exists a table in the destination schema with the same name of the source schema, then it’ll trigger an error (two tables cannot have the same name in a schema, it needs to be unique).
How I can handle if a column doesn’t allow NULL but I want to make clear that a specific value means that row doesn’t have the value?
Use DEFAULT after specifiying NOT NULL in a column definition. For example, DESCRIPTION VARCHAR(20) NOT NULL DEFAULT(‘EMPTY’). This column doesn’t allow NULL, but in case a row is inserted and doesn’t have a value to the DESCRIPTION column, for example, then it’ll take the string ‘EMPTY’ as placeholder to indicate it’s NULL (but it’s not a real NULL).
Can a table have more than an IDENTITY column?
No, it can’t. The IDENTITY is used in this way: IDENTITY(seed value, increment amount). The first parameter is for know with which value is going to begin, and with the increment number each time a row is inserted.
What are the level of table compression?
There’s two table level compression: row level and page level (the page level is deeper than row level compression). To apply the table compression, when the table is being created, it must add the clause WITH (DATA_COMPRESSION = ROW/PAGE) at the bottom of the CREATE statement. Also it can add the compression altering the table.
How a table modification can be achieved?
With the statement ALTER TABLE.
In which case the ALTER TABLE cannot be used?
To rename a column, to add IDENTITY property to a column or to drop IDENTITY property.
What’s declarative data integrity?
Whe you know which column should have unique values, what ranges of valid values a column might accept, and whether a value of the column match some column in a different table. All these methods are aplicated in the table definition.
How is stored a constraint in a database?
As a database object, such as a table, a view, a stored procedure, a function, and so on.