SQL Server Identity and Unique Identifier| SQL Tutorial for Beginners Part 21| Primary Key| NEWID

preview_player
Показать описание
#sql #learnsql Server, how to default to the primary key column using either the Identity(Auto Increment) or unique identifier, where you can use the new ID function. This video discussed that in detail.
#sql #sqltutorial #cursorsinsql #sqltutorials #amitchandakda

Hello and welcome to SQL tutorial for beginners taught by Amit Chandak. In this SQL Tutorial, you will be able to learn ‘cursors in SQL.

-----------------
PRIMARY Key − Identifies each row of a database table uniquely as a row/record in the table.
Identity- Help in creating an identity column in a table. This property is used with the CREATE TABLE and ALTER TABLE Transact-SQL statements.
Unique identifier - In SQL Server, a globally unique identifier (GUID) data type is represented by the uniqueidentifier data type, which stores a 16-byte binary value. GUIDs are binary numbers that are used as identifiers in networks with many computers at different locations, as they must be unique.
-------------------
-- Create a table with an identity column
CREATE TABLE ExampleTable (
ID INT IDENTITY(1,1) PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);

-- Insert some sample data
INSERT INTO ExampleTable (FirstName, LastName, Email)

select * from ExampleTable

INSERT INTO ExampleTable (FirstName, LastName, Email)

INSERT INTO ExampleTable (FirstName, LastName, Email)

select * from ExampleTable

-- Create a table with an identity column
CREATE TABLE ExampleTable1 (
ID INT IDENTITY(1,1) PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);

-- Insert some sample data
INSERT INTO ExampleTable1 (FirstName, LastName, Email)

select * from ExampleTable1

INSERT INTO ExampleTable1 (FirstName, LastName, Email)

INSERT INTO ExampleTable1 (FirstName, LastName, Email)

select * from ExampleTable
select * from ExampleTable1
--------------------

CREATE TABLE ExampleTable2 (
ID UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);

-- Insert some sample data without specifying a value for ID (it will use the default)
INSERT INTO ExampleTable2 (FirstName, LastName, Email)

select * from ExampleTable2

INSERT INTO ExampleTable2 (FirstName, LastName, Email)

INSERT INTO ExampleTable2 (FirstName, LastName, Email)

select * from ExampleTable2

--------------

CREATE TABLE ExampleTable3 (
ID UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);

-- Insert some sample data without specifying a value for ID (it will use the default)
INSERT INTO ExampleTable3 (FirstName, LastName, Email)

INSERT INTO ExampleTable3 (FirstName, LastName, Email)

INSERT INTO ExampleTable3 (FirstName, LastName, Email)

select * from ExampleTable3
select * from ExampleTable2

#sql #sqltutorial #cursorsinsql #sqltutorials #amitchandakda

▶️Follow me on:

-~-~~-~~~-~~-~-
Please watch: "Microsoft Power BI Tutorial For Beginners✨ | Power BI Full Course 2023 | Learn Power BI"
-~-~~-~~~-~~-~-
Рекомендации по теме
welcome to shbcf.ru