Another fantastic SQL Tutorial brought to you by BeardedDev.
In this video we look at what Primary Keys are and how to add Primary Keys within Create Table statements or Alter Table statements: • SQL Tutorial - PRIMARY KEY CONSTRAINTS
If you are new to primary keys this tutorial will help you know how to add primary keys by using object explorer and tsql.
If you want to know what a composite primary key is watch this video: • SQL Tutorial - PRIMARY KEY CONSTRAINTS
If you are interested in learning how to add constraints to tables in SQL Server check out this link: • SQL Tutorial - Create Table with Cons...
For more great instructional videos on data development or business intelligence click here to see all the videos available on my channel: / @beardeddevdata
SQL:
IF OBJECT_ID(N'dbo.Customers', N'U') IS NOT NULL
DROP TABLE dbo.Customers;
GO
CREATE TABLE dbo.Customers
(
CustomerId INT IDENTITY(1, 1) NOT NULL
, FirstName NVARCHAR(50) NOT NULL
, MiddleName NVARCHAR(50) NOT NULL
, LastName NVARCHAR(50) NOT NULL
, DOB DATE NULL
, Email NVARCHAR(100) NULL
, HomeTel VARCHAR(20) NULL
, MobileTel VARCHAR(20) NULL
, [1stLineAddress] VARCHAR(100) NULL
, City INT NULL
, County INT NULL
, Country INT NULL
)
IF OBJECT_ID(N'dbo.Customers', N'U') IS NOT NULL
DROP TABLE dbo.Customers;
GO
CREATE TABLE dbo.Customers
(
CustomerId INT IDENTITY(1, 1) NOT NULL
CONSTRAINT PK_Customers_CustomerID PRIMARY KEY (CustomerId)
, FirstName NVARCHAR(50) NOT NULL
, MiddleName NVARCHAR(50) NOT NULL
, LastName NVARCHAR(50) NOT NULL
, DOB DATE NULL
, Email NVARCHAR(100) NULL
, HomeTel VARCHAR(20) NULL
, MobileTel VARCHAR(20) NULL
, [1stLineAddress] VARCHAR(100) NULL
, City INT NULL
, County INT NULL
, Country INT NULL
)
ALTER TABLE dbo.Customers
ADD CONSTRAINT PK_Customers_CustomerId PRIMARY KEY (CustomerId)
SELECT * FROM sys.key_constraints
Don't forget to subscribe to the channel and let me know your thoughts in the comments section below.
Watch video SQL Tutorial - PRIMARY KEY CONSTRAINTS online without registration, duration hours minute second in high quality. This video was added by user BeardedDev 10 December 2017, don't forget to share it with your friends and acquaintances, it has been viewed on our site 9,39 once and liked it 9 people.