SQL Server如何在同一数据库中的表之间维护GUID [英] SQL Server how to maintain GUID across tables in same DB
本文介绍了SQL Server如何在同一数据库中的表之间维护GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个数据库,其中每个表的PK将是GUID,并且在整个数据库中是唯一的
I want to create a DB , where each table's PK will be GUID and which will be unique across the DB,
示例:我的数据库名称为"LOCATION".我有3个表,分别为"CITY","STATE"和"COUNTRY".
Example: my DB name is 'LOCATION'. And I have 3 table as 'CITY' , 'STATE' and 'COUNTRY'.
我希望所有3个表都具有与GUID相同的PK字段,并且该值在数据库中将是唯一的.
I want that all the 3 tables have same PK field as GUID ,and that value will be unique across DB.
如何在SQL Server中执行此操作,知道吗?我以前从未使用过SQL Server,因此如果进行简要说明,它将很有帮助.
How to do this in SQL Server, any idea? I have never used SQL Server before, so it will be helpful if briefly explained.
推荐答案
create table CITY (
ID uniqueidentifier not null primary key default newid(),
.
.
.
)
重复其他表格.
这篇关于SQL Server如何在同一数据库中的表之间维护GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文