الجدول الرئيسي انشأته بـ sql server وهذا الكود الخاص به :
USE [db1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[table_main](
[file_type] [int] NOT NULL,
[file_no] [int] NOT NULL,
[file_date] [date] NULL,
[descr] [nvarchar](50) NULL,
CONSTRAINT [PK_table_main] PRIMARY KEY CLUSTERED
(
[file_type] ASC,
[file_no] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
الجدول الفرعي انشأته بـ sql server وهذا الكود الخاص به :
USE [db1]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[table_sub](
[file_type] [int] NOT NULL,
[file_no] [int] NOT NULL,
[file_srno] [int] IDENTITY(1,1) NOT NULL,
[descr] [nvarchar](100) NULL,
CONSTRAINT [PK_table_sub] PRIMARY KEY CLUSTERED
(
[file_type] ASC,
[file_no] ASC,
[file_srno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[table_sub] WITH CHECK ADD CONSTRAINT [FK_table_sub_table_main] FOREIGN KEY([file_type], [file_no])
REFERENCES [dbo].[table_main] ([file_type], [file_no])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[table_sub] CHECK CONSTRAINT [FK_table_sub_table_main]
GO
السؤال
Naser ناصر
السلام عليكم
اريد انشاء جدولين في قاعدة بيانات MYSQL
جدول رئيسي master
وجدول فرعي له details
وبينها علاقة many to one relationship
الجدول الرئيسي انشأته بـ sql server وهذا الكود الخاص به :
USE [db1] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[table_main]( [file_type] [int] NOT NULL, [file_no] [int] NOT NULL, [file_date] [date] NULL, [descr] [nvarchar](50) NULL, CONSTRAINT [PK_table_main] PRIMARY KEY CLUSTERED ( [file_type] ASC, [file_no] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO
الجدول الفرعي انشأته بـ sql server وهذا الكود الخاص به :
USE [db1] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[table_sub]( [file_type] [int] NOT NULL, [file_no] [int] NOT NULL, [file_srno] [int] IDENTITY(1,1) NOT NULL, [descr] [nvarchar](100) NULL, CONSTRAINT [PK_table_sub] PRIMARY KEY CLUSTERED ( [file_type] ASC, [file_no] ASC, [file_srno] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[table_sub] WITH CHECK ADD CONSTRAINT [FK_table_sub_table_main] FOREIGN KEY([file_type], [file_no]) REFERENCES [dbo].[table_main] ([file_type], [file_no]) ON UPDATE CASCADE ON DELETE CASCADE GO ALTER TABLE [dbo].[table_sub] CHECK CONSTRAINT [FK_table_sub_table_main] GO
فكيف انشاء اكود مثلهما تعمل في mysql
4 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.