Sample Table Using the uniqueidentifier and NEWID() Function : uniqueidentifier « Constraints « SQL Server / T-SQL Tutorial






4>
5> CREATE TABLE MyTable(
6>  PK_ID     uniqueidentifier NOT NULL
7>                             PRIMARY KEY
8>                             DEFAULT (NEWID ()),
9>  Name char (30)     NOT NULL
10> )
11> GO
1> INSERT MyTable (Name) VALUES ('F')
2> INSERT MyTable (Name) VALUES ('W')
3>
4>
5> select * from MyTable
6> GO

(1 rows affected)

(1 rows affected)
PK_ID                                Name
------------------------------------ ------------------------------
FABC1C4A-C8F9-4E2B-B648-0550D95A0EC6 F
6B9035E9-9A27-4D0A-820C-F19589CD1965 W

(2 rows affected)
1>
2> drop table MyTable
3> GO
1>








7.11.uniqueidentifier
7.11.1.Sample Table Using the uniqueidentifier and NEWID() Function