what is Constraint? How many types of constraints in SQL ?
Answer Posted / kannan
SQL Server constraints allow you to enforce rules in your
database. These rules may affect business logic, database
integrity and/or table structures. Each one plays an
important role in your database architecture. The six types
of constraints supported by Microsoft SQL Server include:
UNIQUE constraints allow SQL Server administrators to
specify that a column may not contain duplicate values. When
you create a new UNIQUE constraint, SQL Server checks the
column in question to determine whether it contains any
duplicate values. If the table contains preexisting
duplicates, the constraint creation command fails.
Similarly, once you have a UNIQUE constraint on a column,
attempts to add or modify data that would cause duplicates
to exist also fail.
CHECK constraints allow you to limit the types of data
that users may insert in a database. They go beyond data
types and allow you to define the specific values that may
be included in a column.
DEFAULT constraints allow you to specify a value that
the database will use to populate fields that are left blank
in the input source. They're a replacement for the use of
NULL values that provide a great way to predefine common
data elements.
NOT NULL constraints allow you to specify that a column
may not contain NULL values. When you create a new NOT NULL
constraint on a database column, SQL Server checks the
column's current contents for any NULL values. If the column
currently contains NULL values, the constraint creation
fails. Otherwise, SQL Server adds the NOT NULL constraint
and any future INSERT or UPDATE commands that would cause
the existence of a NULL value fail.
PRIMARY KEY constraints specify fields that uniquely
identify each record in the table. It can either be a normal
attribute that is guaranteed to be unique (such as Social
Security Number in a table with no more than one record per
person) or it can be generated by the DBMS (such as a
globally unique identifier, or GUID, in Microsoft SQL
Server). Primary keys may consist of a single attribute or
multiple attributes in combination.
FOREIGN KEY constraints are fields in a relational
database table that match the primary key column of another
table. Foreign keys can be used to cross-reference tables.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
You are doing log shipping due to some reasons it is failing. How you will proceed from there
Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?
What is the difference between coalesce() & isnull()?
Mention the differences between sql server and mysql.
Difference between Inner vs outer joins?
What are the dis_advantages of stored procedures, triggers, indexes?
Can we add a cpu to sql server?
How does using a separate hard drive for several database objects improves performance right away?
i have made a project i vb.net n created a .exe of it after installing it in to any pc, the database (sql express) is not geting accesed i.e the aplication cuts the link of the database, so plz help in this matter.
Explain how you can deploy an SSRS report?
What stored by the msdb? : sql server database administration
explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration
What is a field name?
Do you know what is rank function?
How to list all columns in a table using odbc_columns()?