--创建前先查询是否存在
if exists (select * from sys.databases where name="Users(数据库名字)")
drop database Users(数据库名字)
go--创建数据库
create
--使用该数据库
use
--创建表
create table usertable(表名字)
(
)
--科目
Create table CoursTable
(
)
--创建外键
alter table UserTable
add constraint Fk_UserTable_Ut_Strong_Ct_Id foreign key (Ut_Strong_Ct_Id) references CoursTable (Ct_Id)
--为表添加描述信息
EXECUTE sp_addextendedproperty N'MS_Description', '会员表(表描述)', N'user', N'dbo', N'table', N'usertable(表名字)', NULL, NULL
--为字段Ut_Email添加描述信息
EXECUTE sp_addextendedproperty N'MS_Description', '邮箱(字段描述)', N'user', N'dbo', N'table', N'usertable(表名字)', N'column', N'Ut_Email(字段名)'
--更新表中列Ut_Email的描述属性:
EXEC sp_updateextendedproperty 'MS_Description','字段描述','user',dbo,'table','usertable(表名字)','column',Ut_Email(字段名)
--显示Ut_Email字段的描述属性
SELECT
FROM
--显示表的描述属性
SELECT
FROM
--删除表中列Ut_Email的描述属性
EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','usertable(表名字)','column',Ut_Email(字段名)
--删除表
drop table usertable(表名字)
--删除数据库
drop database Users(数据库名字)
--新建存储过程(用存储过程建表)
Create procedure CreateTable(存储过程名)
(
@tablename nvarchar(50)(参数)
)
as(执行开始)
declare @table nvarchar(1500)(声明变量)
set @table = '
Create table [' + @tablename + 'Article]
(
Article_ID int not null primary key identity(1,1),
Article_Head nvarchar(20) not null,
Article_Text text not null,
Article_ListID int not null,
Article_Time datetime not null default(getdate()),
Article_Delete bit not null default(0),
)
Create table [' + @tablename + 'Photos]
(
)
Create table [' + @tablename + 'Moods]
(
)
Create table [' + @tablename + 'List]
(
)
alter table [' + @tablename + 'Article]
add constraint Fk_Article_Article_ListID_List_List_ID foreign key
(Article_ListID) references [' + @tablename + 'List] (List_ID)
'(设置@table语句为)
exec(@table) (执行改sql语句)