What Is A Constraint?
What Is A Constraint?
What Is A Constraint?
Constraint can be used to specify the limit on the data type of table. Constraint can be specified
while creating or altering the table statement. Sample of constraint are.
NOT NULL.
CHECK.
DEFAULT.
UNIQUE.
PRIMARY KEY.
FOREIGN KEY.
Data Integrity defines the accuracy and consistency of data stored in a database. It can also
define integrity constraints to enforce business rules on the data when it is entered into the
application or database.
Auto increment keyword allows the user to create a unique number to be generated when a new
record is inserted into the table. AUTO INCREMENT keyword can be used in Oracle and
IDENTITY keyword can be used in SQL SERVER.
Clustered index is used for easy retrieval of data from the database by altering the way that the
records are stored. Database sorts out rows by the column which is set to be clustered index.
A nonclustered index does not alter the way it was stored but creates a complete separate object
within the table. It point back to the original table rows after searching.
Collation is defined as set of rules that determine how character data can be sorted and compared.
This can be used to compare A and, other language characters and also depends on the width of
the characters.
UNION operator is used to combine the results of two tables, and it eliminates duplicate rows
from the tables.
MINUS operator is used to return rows from the first query but not from the second query.
Matching records of first and second query and other rows from the first query will be displayed
as a result set.
INTERSECT operator is used to return rows returned by both the queries. common records
from two tables
Aggregate functions are used to evaluate mathematical calculation and return single values. This
can be calculated from the columns in a table. Scalar functions return a single value based on the
input value.
Example -.
45. How can you create an empty table from an existing table?
Records can be fetched for both Odd and Even row numbers -.
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
To display odd numbers-.
Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
Studentname does not start with any single character between a and p
UPPER(), LOWER()
-------------------
SELECT NULL + 5
SELECT NULL + 1
SQL Server does not support function-based indexes as described but it does
offer computed columns that can be used instead.
After every index change, update the statistics for the base table and all its indexes.
Databases with an execution plan cache like SQL Server and the
Oracle database can reuse an execution plan when executing the same
statement multiple times. It saves effort in rebuilding the execution
plan but works only if the SQL statement is exactly the same. If you put
different values into the SQL statement, the database handles it like a
different statement and recreates the execution plan.
When using bind parameters (parameterized queries) you do not write the actual values but
instead insert placeholders into the SQL statement. That way the
statements do not change when executing them with different values.
Fill factor is the term associated with indexes actually with clustured indexes
Whenever a clustured index is created sql server physically orders data in basis of the clustured
column. As you must be aware that the data is sql server is stored in 8K data page. Fill factor
value setting advice SQL Server to leave specified amount of space free on each page inorder to
accommodate new data if no fill factor is set SQL Server data page will be filled completely and
incase a new record comes it will have to make space in the data page by reorganizing rest of the
pages which is an over head. And hence it is suggested to keep reasonable value for fill factor
considering future requirements.