多表的建立 (一) 表的腳本
搞了好久都沒有搞懂1.2的1對多關系是怎麼建立,後來參照官方api一點一點的試,終于成功了一次.
應為我的網速慢,所以分快加入.
應為我的網速慢,所以分快加入.
1if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DataZJ]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
2drop table [dbo].[DataZJ]
3GO
4
5if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserZJ]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
6drop table [dbo].[UserZJ]
7GO
8
9CREATE TABLE [dbo].[DataZJ] (
10 [Meid] [int] IDENTITY (1, 1) NOT NULL ,
11 [xb] [bigint] NULL ,
12 [sr] [datetime] NULL ,
13 [dz] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
14) ON [PRIMARY]
15GO
16
17CREATE TABLE [dbo].[UserZJ] (
18 [id] [int] IDENTITY (1, 1) NOT NULL ,
19 [zname] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
20 [Meid] [int] NULL
21) ON [PRIMARY]
22GO
23
24ALTER TABLE [dbo].[DataZJ] ADD
25 CONSTRAINT [PK_DataZJ] PRIMARY KEY CLUSTERED
26 (
27 [Meid]
28 ) ON [PRIMARY]
29GO
30
31ALTER TABLE [dbo].[UserZJ] ADD
32 CONSTRAINT [PK_UserZJ] PRIMARY KEY CLUSTERED
33 (
34 [id]
35 ) ON [PRIMARY]
36GO
37
38
2drop table [dbo].[DataZJ]
3GO
4
5if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserZJ]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
6drop table [dbo].[UserZJ]
7GO
8
9CREATE TABLE [dbo].[DataZJ] (
10 [Meid] [int] IDENTITY (1, 1) NOT NULL ,
11 [xb] [bigint] NULL ,
12 [sr] [datetime] NULL ,
13 [dz] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
14) ON [PRIMARY]
15GO
16
17CREATE TABLE [dbo].[UserZJ] (
18 [id] [int] IDENTITY (1, 1) NOT NULL ,
19 [zname] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
20 [Meid] [int] NULL
21) ON [PRIMARY]
22GO
23
24ALTER TABLE [dbo].[DataZJ] ADD
25 CONSTRAINT [PK_DataZJ] PRIMARY KEY CLUSTERED
26 (
27 [Meid]
28 ) ON [PRIMARY]
29GO
30
31ALTER TABLE [dbo].[UserZJ] ADD
32 CONSTRAINT [PK_UserZJ] PRIMARY KEY CLUSTERED
33 (
34 [id]
35 ) ON [PRIMARY]
36GO
37
38