Describe the use of primary key and unique key constraints with example?

1 Answer

Answer :

There are two Entity constraints:

1.Primary Key constraint

2. Unique Constraint

1. Primary Key constraint: It is use to avoid redundant/duplicate value entry within the row of specified column in table. It restricts null values too.

Syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME

DATA_TYPE, COLUMN_NAME DATA_TYPE CONSTRAINT

CONSTRAINT_NAME PRIMARY KEY);

Example: SQL> CREATE TABLE EMP (ID NUMBER

(5)CONSTRAINT ID_PK PRIMARY KEY, NAME VARCHAR2

(10), SAL NUMBER (10));

2. Unique Constraint: The UNIQUE constraint uniquely identifies each record in a database table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. 

syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME

DATA_TYPE, COLUMN_NAME DATA_TYPE CONSTRAINT

CONSTRAINT_NAME UNIQUE);

Example: CREATE TABLE PERSONS (P_ID NUM CONSTRAINT

P_UK UNIQUE , FIRSTNAME VARCHAR(20), CITY

VARCHAR(20) );

Related questions

Description : What is difference between UNIQUE and PRIMARY KEY constraints?

Last Answer : A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.

Description : In an LPP, if the solution of a variable can be made infinitely large without violating the constraints, then the solution is .............................. a. Infeasible b. Alternative c. Unbounded d. Unique

Last Answer : c. Unbounded

Description : Write any one similarity and one difference between primary key and unique Constraint. -Technology

Last Answer : Similarity: Column with both the constraints will only take unique values.Difference: Column with Primary key constraints will not be able to hold NULL values while Column with Unique constraints will be able to hold NULL values.

Description : Write any one similarity and one difference between primary key and unique Constraint -Technology

Last Answer : Similarity: Column with both the constraints will only take unique values.Difference: Column with Primary key constraints will not be able to hold NULL values while Column with Unique constraints will be able to hold NULL values.

Description : What is the difference between candidate key, unique key and primary key

Last Answer : Candidate keys are the columns in the table that could be the primary keys and the primary key is the key that has been selected to identify the rows. Unique key is also useful for identifying the distinct rows in the table.)

Description : What is difference between UNIQUE constraint and PRIMARY KEY constraint ?

Last Answer : A column defined as UNIQUE can contain Nulls while a column defined as PRIMARY KEY can't contain Nulls.

Description : What is the difference between unique key and primary key ?

Last Answer : Unique key can be null; Primary key cannot be null.

Description : What is difference between UNIQUE constraint and PRIMARY KEY constraint?

Last Answer : A column defined as UNIQUE can contain Nulls while a column defined as PRIMARY KEY can’t contain Nulls. 47.What is Index Cluster? – A Cluster with an index on the Cluster Key 48.When does a Transaction end? – When it is committed or Rollbacked.

Description : Consider the following database table : Create table test( one integer, two integer, primary key(one), unique(two), check(one≥1 and ≤10), check(two≥1 and ≤5) ); How many data records/tuples atmost can this table contain ?  (A) 5 (B) 10 (C) 15 (D) 50

Last Answer : (A) 5 

Description : State the use of sequence.

Last Answer : A sequence refers to a database object that is capable of generating unique and sequential integer values. Syntax: Create sequence [increment by num][start with num] [maxvaluenum] [ ... can be used for multiple tables. * Sequence numbers are stored and generated independently of tables

Description : State the use of ‘Like’ Operator.

Last Answer : The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two operator often used in conjunction with the LIKE operator:  %:The percent sign represents zero, one, or multiple characters  _: The underscore represents a single character.

Description : State the properties of Transaction

Last Answer : The ACID properties of transaction. 1. Atomicity. 2. Consistency. 3. Isolation.  4. Durability

Description : Enlist different types of database users.

Last Answer : Database users are the one who really use and take the benefits of database. There will be different types of users depending on their need and way of accessing the database. 1. Application Programmers 2. Sophisticated Users 3. Specialized Users 4. Native Users/ Naïve Users

Description : List the types of Cursor.

Last Answer : Cursor: A cursor is a temporary work area created in the system memory when a SQL statement is executed. Types of Cursor: 1.Implicit Cursor 2.Explicit Cursor

Description : Write syntax to create view.

Last Answer : Create view as select OR CREATE VIEW name ASSELECT column1, column2.....FROM table_nameWHERE [condition];

Description : Which of the following are NOT key constraints of the food processing industry? a) Inadequate quality control. c) High packaging cost b) Low demand. d) Poor infrastructure as in no cold storage

Last Answer : Low demand.

Description : Based on the cardinality ratio and participation ............... associated with a relationship type, choose either the Foreign Key Design, the Cross Referencing Design or Mutual Referencing Design. (A) Entity (B) Constraints (C) Rules (D) Keys

Last Answer : (B) Constraints

Description : Explain Domain constraints with Syntax and example. 

Last Answer : Domain constraints are used to maintain value according to user specification Domain constraints are: 1. Not null-such constraints are applied to an attribute when we have to specify that the ... datatype(size),attr2 datatype(size) constraint nameofconstraint check(attr<value)); or

Description : Define primary key with an example. -Technology

Last Answer : A field which uniquely identifies each record in a table is known as the primary key. e.g. emp id is the primary key of the Employee table.

Description : What is primary key? Give an example. -Technology

Last Answer : A field which uniquely identifies each record in a table is known as the primary key. e.g. emp id is the primary key of the Employee table.

Description : What is a primary key in database? Give an example. -Technology

Last Answer : A field which uniquely identifies each record in a table is known as the primary key. e.g. emp id is the primary key of the Employee table.

Description : Key field is a unique identifier for each record. It is defined in the form of (a) rows (b) columns -Technology

Last Answer : (b) Key is a data item that allows you to uniquely identify individual occurrences which is defined as the column or set of columns.

Description : If an unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE ?

Last Answer : It won't, Because SYSDATE format contains time attached with it.

Description : What’s the .NET collection class that allows an element to be accessed using a unique key? 

Last Answer : HashTable. 

Description : What’s the .NET collection class that allows an element to be accessed using a unique key?

Last Answer : HashTable.

Description : A digital signature is a. a bit string giving identity of a correspondent b. a unique identification of a sender c. an authentication of an electronic record by tying it uniquely to a key only a sender knows d. an encrypted signature of a sender 

Last Answer : c. an authentication of an electronic record by tying it uniquely to a key only a sender knows

Description : The activities in a project must be …. a. Unique b. Primary c. Important d. None of the above

Last Answer : a. Unique

Description : What is the use of CONSTRAINTS option in EXP command ?

Last Answer : A flag to indicate whether constraints on table need to be exported.

Description : What is the benefit of the expertise of a licensed architect in a virtual environment that does not have the inherent constraints of physics.

Last Answer : Infinite proportions.

Description : The tensor product technique constraints surfaces by two curves. a.2 b.1 c.3 d.4

Last Answer : b.1

Description : Mention three constraints explaining why cultivable waste land is not being used for cultivation at present. -Geography

Last Answer : The constraints are : 1. Due to human neglect, large tracts of land of U.P., Punjab and Haryana turned infertile due to salinity or alkalinity of soil. 2. Due to extensive soil ... the soil resulting from faulty agricultural practices, large tracts of land now, can not be used for agriculture.

Description : What Difference between disjoint and overlapping constraints?

Last Answer : Need answer

Description : What is a criteria and constraints.?

Last Answer : Your criteria is(goals) and constraints are(limits).

Description : Taxes are as certain as the death, because - (1) They constitute the major source of government revenue. (2) Government have no other source of revenue. (3) Most PSUs are run inefficiently. (4) Government has its own budget constraints.

Last Answer : (1) They constitute the major source of government revenue. Explanation: Benjamin Franklin's utterance, "In this world nothing can be said to be certain, except death and taxes," when applied ... draws on the actual inevitability of death to highlight the difficulty in avoiding the burden of taxes.

Description : Give two examples of referential integrity constraints.

Last Answer : rential integrity constraints.

Description : Where the integrity constraints are stored in Data Dictionary ?

Last Answer : The integrity constraints are stored in USER_CONSTRAINTS.

Description : How will you a activate/deactivate integrity constraints ?

Last Answer : The integrity constraints can be enabled or disabled by ALTER TABLE ENABLE constraint/DISABLE constraint.

Description : What are various constraints used in SQL?

Last Answer : NULL -NOT NULL -CHECK -DEFAULT

Description : How do you control the constraints in forms ?

Last Answer : Select the use constraint property is ON Block definition screen.BLOCK

Description : What are the operating constraints imposed in the load flow studies?

Last Answer : The operating constraints imposed in load flow studies are reactive power limits for generator buses and allowable change in magnitude of voltagefor load buses.

Description : Which of these is not one of the constraints of a project? a. Scope b. Resources c. Team d. Budget

Last Answer : c. Team

Description : What is the first step in project planning? Select one: a. Establish the objectives and scope. b. Determine the budget. c. Select the team organizational model. d. Determine project constraints. e. Inspect the deliverables.

Last Answer : a. Establish the objectives and scope.

Description : According to the Project Management Institute (PMI), the scope statement should  address all of the following issues EXCEPT: Select one: a. project constraints. b. project assumptions c. project ... d. code of conduct for the team members working on the project. e. project deliverables.

Last Answer : d. code of conduct for the team members working on the project.

Description : What is the first step in project planning? Select one: a. Establish the objectives and scope. b. Determine the budget. c. Select the team organizational model. d. Determine project constraints. e. Inspect the deliverables.

Last Answer : a. Establish the objectives and scope.

Description : Your company has asked you to be the project manager for the product introduction  of its new DeskTop Rock media system. You recently published the project scope  statement. Which ... . Constraints  B. Project specifications  C. Requested changes D. Project configuration management requirements

Last Answer : C. Requested changes

Description : Which of these is not one of the constraints of a project? a. Scope b. Resources c. Team d. Budget

Last Answer : c. Team

Description : The Scope Statement should contain which of the following? 1. Project schedule  2. Project budget constraints  3. Summary of project tasks , deliverables and resources required  4. Project objectives

Last Answer : 4. Project objectives

Description : During the planning development process, at times it is necessary to make certain assumptions to enhance the project plan when the data is not available. In regard to making those assumptions, ... upon historical data used for the project.  4. Senior management predefines the budget constraints.

Last Answer : 1. The assumptions will be considered as true, real, or certain.

Description : Which of these is not one of the constraints of a project? A. Scope B. Resources C. Team D. Budget

Last Answer : C. Team