从一个表中导数据到另一个表的SQL
1--1.菜单表
2
3DROP TABLE dbo.Menu
4go
5
6
7CREATE TABLE dbo.Menu
8(
9 MenuID bigint NOT NULL ,
10 MenuName nvarchar(200) NULL ,
11 ParentID bigint NOT NULL ,
12 URL nvarchar(200) NULL ,
13 OrderIndex bigint NOT NULL
14)
15go
16
17
18exec sp_addextendedproperty 'MS_Description' , '菜单' , 'user' , 'dbo' , 'table' , 'Menu'
19go
20
21
22exec sp_addextendedproperty 'MS_Description' , '菜单ID' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'MenuID'
23go
24
25
26exec sp_addextendedproperty 'MS_Description' , '菜单名称' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'MenuName'
27go
28
29
30exec sp_addextendedproperty 'MS_Description' , '父菜单ID' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'ParentID'
31go
32
33
34exec sp_addextendedproperty 'MS_Description' , '超链接' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'URL'
35go
36
37
38exec sp_addextendedproperty 'MS_Description' , '排序' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'OrderIndex'
39go
40
41
42ALTER TABLE dbo.Menu
43 ADD PRIMARY KEY (MenuID ASC)
44go
45
46--2.类别表
47DROP TABLE dbo.Category
48go
49
50
51CREATE TABLE dbo.Category
52(
53 CategoryID bigint NOT NULL ,
54 CategoryName nvarchar(100) NULL ,
55 ParentID bigint NOT NULL ,
56 OrderIndex bigint NOT NULL
57)
58go
59
60
61exec sp_addextendedproperty 'MS_Description' , '种类' , 'user' , 'dbo' , 'table' , 'Category'
62go
63
64
65exec sp_addextendedproperty 'MS_Description' , '种类ID' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'CategoryID'
66go
67
68
69exec sp_addextendedproperty 'MS_Description' , '种类名称' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'CategoryName'
70go
71
72
73exec sp_addextendedproperty 'MS_Description' , '父种类ID' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'ParentID'
74go
75
76
77exec sp_addextendedproperty 'MS_Description' , '排序' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'OrderIndex'
78go
79
80
81ALTER TABLE dbo.Category
82 ADD PRIMARY KEY (CategoryID ASC)
83go
84
85
86--3.菜单里面一部分数据导到类别表中的SQL
87
88Insert Into Category(CategoryID, CategoryName, ParentID, OrderIndex)
89 Select MenuID, MenuName, ParentID, OrderIndex
90 From Menu
91 Where MenuID<51
92
93
2
3DROP TABLE dbo.Menu
4go
5
6
7CREATE TABLE dbo.Menu
8(
9 MenuID bigint NOT NULL ,
10 MenuName nvarchar(200) NULL ,
11 ParentID bigint NOT NULL ,
12 URL nvarchar(200) NULL ,
13 OrderIndex bigint NOT NULL
14)
15go
16
17
18exec sp_addextendedproperty 'MS_Description' , '菜单' , 'user' , 'dbo' , 'table' , 'Menu'
19go
20
21
22exec sp_addextendedproperty 'MS_Description' , '菜单ID' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'MenuID'
23go
24
25
26exec sp_addextendedproperty 'MS_Description' , '菜单名称' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'MenuName'
27go
28
29
30exec sp_addextendedproperty 'MS_Description' , '父菜单ID' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'ParentID'
31go
32
33
34exec sp_addextendedproperty 'MS_Description' , '超链接' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'URL'
35go
36
37
38exec sp_addextendedproperty 'MS_Description' , '排序' , 'user' , 'dbo' , 'table' , 'Menu', 'column' , 'OrderIndex'
39go
40
41
42ALTER TABLE dbo.Menu
43 ADD PRIMARY KEY (MenuID ASC)
44go
45
46--2.类别表
47DROP TABLE dbo.Category
48go
49
50
51CREATE TABLE dbo.Category
52(
53 CategoryID bigint NOT NULL ,
54 CategoryName nvarchar(100) NULL ,
55 ParentID bigint NOT NULL ,
56 OrderIndex bigint NOT NULL
57)
58go
59
60
61exec sp_addextendedproperty 'MS_Description' , '种类' , 'user' , 'dbo' , 'table' , 'Category'
62go
63
64
65exec sp_addextendedproperty 'MS_Description' , '种类ID' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'CategoryID'
66go
67
68
69exec sp_addextendedproperty 'MS_Description' , '种类名称' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'CategoryName'
70go
71
72
73exec sp_addextendedproperty 'MS_Description' , '父种类ID' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'ParentID'
74go
75
76
77exec sp_addextendedproperty 'MS_Description' , '排序' , 'user' , 'dbo' , 'table' , 'Category', 'column' , 'OrderIndex'
78go
79
80
81ALTER TABLE dbo.Category
82 ADD PRIMARY KEY (CategoryID ASC)
83go
84
85
86--3.菜单里面一部分数据导到类别表中的SQL
87
88Insert Into Category(CategoryID, CategoryName, ParentID, OrderIndex)
89 Select MenuID, MenuName, ParentID, OrderIndex
90 From Menu
91 Where MenuID<51
92
93