Nigel  Uys

Nigel Uys

1670654955

Define A UNIQUE Key in Vertabelo

Among the many database constraints available to us, the UNIQUE key constraint ensures the uniqueness of data in a column or a set of columns. Read on to find out more about the UNIQUE key constraint and how to define it in Vertabelo.

In this article, we’ll focus on the UNIQUE key constraint. We’ll start with its basic definition and usage and gradually build up to more advanced options. Also, we’ll jump into Vertabelo and create an ER diagram that uses the UNIQUE key constraint. You’ll see that the UNIQUE key offers different options in various database engines.

Let’s get started.

What Is a UNIQUE Key Constraint?

The UNIQUE key is one of the database constraints that allow you to set rules for your data. It prevents the column from storing duplicate values.

You can learn about  the OTHER DATABASE CONSTRAINTS IN THIS ARTICLE.

UNIQUE Key on a Single Column

Let’s look at the various ways we can define the UNIQUE key constraint on a single column.

1.      During table creation

The UNIQUE key constraint can be defined with the column definitions, like this …

CREATE TABLE Persons (

Id int PRIMARY KEY,

FirstName varchar(50),

LastName varchar(50),

SSN varchar(9) UNIQUE);

… or after all the columns are defined, like this:

CREATE TABLE Persons (

Id int PRIMARY KEY,

FirstName varchar(50),

LastName varchar(50),

SSN varchar(9),

CONSTRAINT unique_ssn UNIQUE(SSN));

2.      After table creation

Sometimes, we decide to make a column unique after table creation. Here’s how we do it:

CREATE TABLE Persons (

Id int PRIMARY KEY,

FirstName varchar(50),

LastName varchar(50),

SSN varchar(9));

ALTER TABLE Persons ADD UNIQUE(SSN);

We use the ALTER TABLE statement to add or remove database constraints.

Let’s Test It

The constraint implemented on the SSN column is ready to be tested.

First, we insert some data into our Persons table:

INSERT INTO Persons VALUES(1, 'David', 'Anderson', '123123123');

But what if we insert another data row with the same SSN value?

INSERT INTO Persons VALUES(2, 'Anne', 'Johns', '123123123');

This results in an error:

SQL Error [23505]: ERROR: duplicate key value violates unique constraint "unique_ssn"

  Detail: Key (ssn)=(123123123) already exists.

The UNIQUE key constraint works as expected!

UNIQUE Key on Multiple Columns

Let’s see how to define the UNIQUE key on a set of columns:

CREATE TABLE Persons (

Id int PRIMARY KEY,

FirstName varchar(50),

LastName varchar(50),

SSN varchar(9),

CONSTRAINT unique_name UNIQUE(FirstName, LastName));

Or, after table creation:

ALTER TABLE Persons ADD UNIQUE(FirstName, LastName);

Please note that in this case, only the combination of columns must be unique, but not each column individually. So, the following INSERT statements are all valid.

INSERT INTO Persons VALUES(1, 'David', 'Anderson', '123123123');

INSERT INTO Persons VALUES(2, 'Anne', 'Johns', '123123123');

INSERT INTO Persons VALUES(3, 'David', 'Johns', '123123123');

INSERT INTO Persons VALUES(4, 'Anne', 'Anderson', '123123123');

The UNIQUE key constraint implemented on a set of columns doesn’t let duplicate value groups sneak in, just like the one implemented on a single column doesn’t let duplicate values in.

UNIQUE Key as a Candidate Key

A candidate key is a column or a set of columns that identify each row uniquely. So, the UNIQUE key qualifies to be the candidate key. Check out this ARTICLE TO LEARN MORE ABOUT DATABASE KEYS.

Have you heard about the foreign key constraint? It lets you link data stored in different tables. Get the BASICS ON FOREIGN KEYS IN THIS ARTICLE and then see how to IMPLEMENT FOREIGN KEYS IN A PHYSICAL MODEL HERE!

How to Define a UNIQUE Key Constraint in Vertabelo

In this section, you’ll learn how to define the UNIQUE key in Vertabelo. Also, we’ll take a look at some of the more advanced options.

Basic Definition of a UNIQUE Key in Vertabelo

Let’s define the UNIQUE key constraint in Vertabelo. To do so, create a table and navigate to the Alternate (unique) keys section in the right-side panel.

How to Define a UNIQUE Key in Vertabelo

Now, we are ready to add the UNIQUE key.

How to Define a UNIQUE Key in Vertabelo

Click on the Add key button and expand the data. Don’t forget to name your UNIQUE key constraint by filling in the Name field. To give it some context, use the Comment field. And, most importantly, add the column(s) that will implement this constraint.

That’s all! The UNIQUE key constraint is now ready.

SQL Code is Ready

You can also generate an SQL code like this:

How to Define a UNIQUE Key in Vertabelo

And here it is:

How to Define a UNIQUE Key in Vertabelo

In the next section, you’ll learn about the additional options available in various database engines.

Advanced Options in Various Database Engines

There are quite a few advanced constraint options that are database-specific. Let’s look at them one by one.

Available InOptionDescription
PostgreSQLDeferrable

The available options are DEFERRABLE and NOT DEFERRABLE.

DEFERRABLE means that verification of the constraint takes place after the transaction finishes.  NOT DEFERRABLE indicates that the constraint verification is performed immediately after each statement.

Initially deferred

Here, we have either INITIALLY DEFERRED or INITIALLY IMMEDIATE. These options apply only if the constraint is DEFERRABLE.

INITIALLY DEFERRED means that the constraint check is after every transaction. INITIALLY IMMEDIATE indicates that the constraint check is after each statement.

Index tablespaceThis option lets us define the tablespace where the unique index (associated with the UNIQUE key) resides.
WithThis clause is optional. It specifies storage parameters for a table or index.
MySQLUsingThis clause lets us define the type of the UNIQUE key index, e.g. BTREE or HASH.
Key block sizeThis specifies the size of index key blocks in bytes. The database engine treats it as a hint.
Microsoft SQL ServerIs clusteredThis indicates whether we deal with a clustered or non-clustered index.
WITH index optionsThe WITH clause lets you specify index options, such as FILLFACTOR, PAD_INDEX, or ONLINE.
ON clauseThe ON clause lets you specify the partition scheme name, filegroup name, or default filegroup.

In Vertabelo, you can define your database when creating a new physical model. All the UNIQUE key constraint options are available in the right-side panel.

For PostgreSQL database engine:

How to Define a UNIQUE Key in Vertabelo

For more info, see our article on DATABASE CONSTRAINTS IN POSTGRESQL.

For the MySQL database engine:

How to Define a UNIQUE Key in Vertabelo

For further reading, we have an article about DATABASE CONSTRAINTS IN MYSQL.

For the Microsoft SQL Server database engine:

How to Define a UNIQUE Key in Vertabelo

And here’s an ARTICLE about MICROSOFT SQL SERVER DATABASE CONSTRAINTS.

Database constraints are a crucial part of any database design. Make sure to check out our database-specific articles to learn more about the different constraints available.

Learn More About UNIQUE and Other Database Constraints

The UNIQUE key constraint is a very straightforward concept. It simply prevents duplicate values in a column. Try out some examples on your own and you’ll see!

There are many more database constraints, such as primary and foreign keys, the CHECK constraint, the DEFAULT constraint, and the NOT NULL constraint. Continue to our article on DATABASE CONSTRAINTS: WHAT THEY ARE AND HOW TO DEFINE THEM IN VERTABELO to get a glimpse of them all.

Good luck!

Original article source at: https://www.vertabelo.com/

#unique #key 

Define A UNIQUE Key in Vertabelo
Rupert  Beatty

Rupert Beatty

1670580131

SQL UNIQUE Keyword

UNIQUE Keyword

The UNIQUE keyword or constraint is used to ensure that all values in a column are unique.

SQL UNIQUE ON CREATE TABLE

CREATE TABLE <TABLE_NAME> (
    <COLUMN_NAME> DATATYPE UNIQUE
);

Example

CREATE TABLE Employee (
    EMP_NO Integer UNIQUE
);

SQL UNIQUE ON ALTER TABLE

ALTER TABLE <TABLE_NAME>
ADD UNIQUE (<COLUMN_NAME>);

Example

ALTER TABLE Employee ADD UNIQUE(EMP_NO);

Summary

The UNIQUE constraint makes sure that each value in a column is distinct.

Original article source at: https://www.c-sharpcorner.com/

#sql #keyword #unique 

SQL UNIQUE Keyword
Jack Forbes

Jack Forbes

1619613201

3 Unique PR Trends to Consider in 2021

The pandemic has also changed the role of Public Relations (or PR) in ways that were previously difficult to anticipate. The communications plan and strategy have undergone a major transformation as a result of developments such as remote working.
Will businesses continue to rely on conventional PR without compromising their brand-building efforts? Let’s take a look.

PR Trends to Follow in 2021

  • Predictive Analysis: Predictive analysis techniques may be used to forecast subjects and problems that are likely to pique viewer interest based on historical data patterns. It can also assist in the identification of potential customers by using real-time customer data.

  • Live Streaming and Virtual Events: Another new trend is live streaming of events such as award shows and business conferences, which is growing website traffic and online viewership from around the world.

  • The Impact of Fake News on Public Relations: The rise of many media outlets and social media sites such as Facebook and YouTube has aided the spread of fake news. With the dissemination of disinformation at an all-time high, public relations practitioners must contend with false statements regarding their business or industry.

It will be fascinating to see how corporate PR reacts to this transition and develops their organizational strategy for the next decade as more companies go remote and to online platforms.

Look out for these three powerful PR trends in 2021. With more businesses going remote and to online platforms, these trends are here to stay over the next decade.

**Three Unique PR Trends to Consider in 2021
**

#pr #trends #three #unique #public #relations

3 Unique PR Trends to Consider in 2021

Saurabh Tiwari

1596440433

How to find unique visitors in google analytics - SAUKRIT.COM

Unique visitors in google analytics are the first time visitor on the site or app. A unique visitor or active user chart shows the engagement with your site or app. Google analytics the foremost powerful tool for digital analytics out there these days it’s a tool for data analysis of your site or app.

#unique

How to find unique visitors in google analytics - SAUKRIT.COM