我有一个.sql文件,其中包含架构的定义
`USE [master]
GO
/******Object: Database [Phone] Script Date: 18-05-2020 12:15:46******/
CREATE DATABASE [Phone]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Phone', FILENAME = N'H:\SQL SERVER\MSSQL15.MSSQLSERVER\MSSQL\DATA\Phone.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB )
LOG ON
( NAME = N'Phone_log', FILENAME = N'H:\SQL SERVER\MSSQL15.MSSQLSERVER\MSSQL\DATA\Phone_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB )
WITH CATALOG_COLLATION = DATABASE_DEFAULT
GO
ALTER DATABASE [Phone] SET COMPATIBILITY_LEVEL = 150
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [Phone].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [Phone] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Phone] SET ANSI_NULLS OFF
GO
ALTER DATABASE [Phone] SET ANSI_PADDING OFF
GO
ALTER DATABASE [Phone] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [Phone] SET ARITHABORT OFF
GO
ALTER DATABASE [Phone] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [Phone] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [Phone] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [Phone] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [Phone] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [Phone] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [Phone] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [Phone] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [Phone] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [Phone] SET ENABLE_BROKER
GO
ALTER DATABASE [Phone] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [Phone] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [Phone] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [Phone] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [Phone] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [Phone] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [Phone] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [Phone] SET RECOVERY FULL
GO
ALTER DATABASE [Phone] SET MULTI_USER
GO
ALTER DATABASE [Phone] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [Phone] SET DB_CHAINING OFF
GO
ALTER DATABASE [Phone] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [Phone] SET TARGET_RECOVERY_TIME = 60 SECONDS
GO
ALTER DATABASE [Phone] SET DELAYED_DURABILITY = DISABLED
GO
EXEC sys.sp_db_vardecimal_storage_format N'Phone', N'ON'
GO
ALTER DATABASE [Phone] SET QUERY_STORE = OFF
GO
USE [Phone]
GO
/******Object: Table [dbo].[telephone] Script Date: 18-05-2020 12:15:47******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[telephone](
[Mobile] [varchar](50) NOT NULL,
[First ] [varchar](50) NULL,
[Last ] [varchar](50) NULL,
[Email] [varchar](50) NULL,
[Category] [varchar](50) NULL,
PRIMARY KEY CLUSTERED
(
[Mobile] 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
INSERT [dbo].[telephone] ([Mobile], [First ], [Last ], [Email], [Category]) VALUES (N'0000000', N'xyx', N'xyx', N'xyx@xyx.com', N'HOME')
INSERT [dbo].[telephone] ([Mobile], [First ], [Last ], [Email], [Category]) VALUES (N'0000001', N'm', N'sr', N'yz@zx.in', N'OFFICE')
USE [master]
GO
ALTER DATABASE [Phone] SET READ_WRITE
GO
`
我想用c#来解析这个文件以获得以下信息:1。数据库中的表数2。每个表中的列数3。列的数据类型
有办法吗?我希望该方法是通用的,适用于任何类似的.sql文件。
暂无答案!
目前还没有任何答案,快来回答吧!