1. 程式人生 > >mssql建立資料庫,建立表

mssql建立資料庫,建立表

EXEC sp_configure 'show advanced options',1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell',1
RECONFIGURE

EXEC xp_cmdshell 'mkdir f:\project'
EXEC xp_cmdshell 'mkdir f:\qiyi'

USE master

IF EXISTS(SELECT *FROM sysdatabases WHERE name='School')
	DROP DATABASE School
CREATE DATABASE School
ON PRIMARY
(
NAME='School_data',
SIZE=3MB,
MAXSIZE=100MB,
FILEGROWTH=10%,
FILENAME='f:\project\School_data.mdf'
),
FILEGROUP mygroup
(
NAME='School_data1',
SIZE=3MB,
MAXSIZE=100MB,
FILEGROWTH=10%,
FILENAME='F:\qiyi\School_data1.ndf'
)
LOG ON
(
NAME='School_log',
SIZE=3MB,
FILEGROWTH=10%,
FILENAME='f:\project\School_log.ldf'
),
(
NAME='School_log1',
SIZE=3MB,
FILEGROWTH=10%,
FILENAME='f:\qiyi\School_log1.ldf'
)
USE School
IF EXISTS (SELECT* FROM sysobjects WHERE name='Classes')
	DROP TABLE Classes
CREATE TABLE classes
(
Classid INT IDENTITY(1,1),
ClassName NVARCHAR(50) NOT NULL
)
IF EXISTS (SELECT *FROM sysobjects WHERE name='teacher')
	DROP TABLE teacher
CREATE TABLE Teacher
(
Id INT IDENTITY(1,1),
NAME NVARCHAR(50) NOT NULL,
ClassId INT NOT NULL,
Gender BIT NOT NULL,
Age INT,
Salary MONEY,
Birthary DATETIME
)