[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

How to Turn Rowguid option on via SQL Query?

How do I turn Rowguid option on (= Yes), when I create a table via SQL Query?

(See SQL Server Management Studio, Column properities , Rowguid by default is no).


Test Query Attached.
create table TableA (TableAID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, TableBID int null, constraint PK_TableA primary key (TableAID));
create table TableB (TableBID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, constraint PK_TableB primary key (TableBID));
create table TableA2 (TableA2ID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, TableBID int null, constraint PK_TableA2 primary key (TableA2ID));
create table TableB2 (TableB2ID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, constraint PK_TableB2 primary key (TableB2ID));
create table TableA3 (TableA3ID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, TableB3ID int null, constraint PK_TableA3 primary key (TableA3ID));
create table TableB3 (TableB3ID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, constraint PK_TableB3 primary key (TableB3ID));
create table TableA4 (TableA4ID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, constraint PK_TableA4 primary key (TableA4ID));
create table TableB4 (TableB4ID int identity not null, Name varchar(50) null, rowguid uniqueidentifier default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, constraint PK_TableB4 primary key (TableB4ID));
create table TableA4_TableB4 (TableA4ID int not null, TableB4ID int not null, primary key (TableA4ID, TableB4ID));
alter table TableA add constraint FKTableA_TableB foreign key (TableBID) references TableB;
alter table TableA2 add constraint FKTableA2_TableB2 foreign key (TableBID) references TableB2;
alter table TableA3 add constraint FKTableA3_TableB3 foreign key (TableB3ID) references TableB3;
alter table TableA4_TableB4 add constraint FKTableA4TableB4_TableA4 foreign key (TableA4ID) references TableA4;
alter table TableA4_TableB4 add constraint FKTableA4TableB4_TableB4 foreign key (TableB4ID) references TableB4;

Open in new window

0
Khou
Asked:
Khou
1 Solution
 
dportasCommented:
ROWGUIDCOL:

create table TableA (TableAID int identity not null, Name nvarchar(50) not null, rowguid uniqueidentifier ROWGUIDCOL default (newid()) not null unique, ModifiedDate datetime default (getdate()) not null, TableBID int null, constraint PK_TableA primary key (TableAID));
0
 
KhouAuthor Commented:
Thanks Dportas
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now