using System.Data.SqlClient;
//用SQL语句创建了数据库保存的目录,该例子是D下盘的project文件夹,该步骤可以省略
StringBuilder sb=new StringBuilder();
sb.AppendLine("exec sp_configure 'show advanced option=1',1 go");
sb.AppendLine("reconfigure go");
sb.AppendLine("exec sp_configure 'xp_cmdshell',1 go");
sb.AppendLine("reconfigure go");
sb.AppendLine("mkdir d:\project");
//以下是SQL语句创建数据库,例如创建MySchool数据库
create database MySchool
on primary
(
name='MySchool_data',
filename='D:\project\MySchool_data.mdf',
size=5,
maxsize=50,
filegrowth=10%
)
log on
(
name='MySchool_log',
filename='D:\project\MySchool_log.ldf',
size=2,
filegrowth=1
)
go
//以下是创建表,例如创建Student表,包含自增长 主键 非空 默认等等
create table Student
(
stuNO int not null identity(1,1) primary key,
stuName nvarchar(10) not null,
Age int not null,
phone varchar(13),
Address nvarchar(100) default('地址不详')
)
//用SQL语句创建了数据库保存的目录,该例子是D下盘的project文件夹,该步骤可以省略
StringBuilder sb=new StringBuilder();
sb.AppendLine("exec sp_configure 'show advanced option=1',1 go");
sb.AppendLine("reconfigure go");
sb.AppendLine("exec sp_configure 'xp_cmdshell',1 go");
sb.AppendLine("reconfigure go");
sb.AppendLine("mkdir d:\project");
//以下是SQL语句创建数据库,例如创建MySchool数据库
create database MySchool
on primary
(
name='MySchool_data',
filename='D:\project\MySchool_data.mdf',
size=5,
maxsize=50,
filegrowth=10%
)
log on
(
name='MySchool_log',
filename='D:\project\MySchool_log.ldf',
size=2,
filegrowth=1
)
go
//以下是创建表,例如创建Student表,包含自增长 主键 非空 默认等等
create table Student
(
stuNO int not null identity(1,1) primary key,
stuName nvarchar(10) not null,
Age int not null,
phone varchar(13),
Address nvarchar(100) default('地址不详')
)

