mysql与sqlserver 数据库的编写

sqlserver:

BEGIN
   DECLARE @db NVARCHAR(255);
   SET @db = N'db_bbs';


   USE master;


   -- Create the database if it doesn't exist.
   IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = @db)
      EXECUTE('CREATE DATABASE ' + @db);
   -- Uncomment to create with case-sensitive collation   
   --IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = @db) 
   --   EXECUTE('CREATE DATABASE ' + @db + ' COLLATE Latin1_General_BIN');
      


   -- Make sure columns default to NULL-able.
   EXECUTE('ALTER DATABASE ' + @db + ' SET ANSI_NULL_DEFAULT ON');
END;
GO


USE db_bbs;
GO


--
-- Drop existing tables.
--
BEGIN
   -- First, drop foreign key constraints, so we can drop the tables.
   DECLARE fkcursor CURSOR FOR
      SELECT fk.name, parent.name parent
      FROM dbo.sysobjects fk JOIN dbo.sysobjects parent ON fk.parent_obj = parent.id
      WHERE OBJECTPROPERTY(fk.id, N'IsForeignKey') = 1 AND parent.name LIKE 'Ae%'
   DECLARE @name NVARCHAR(255)
   DECLARE @parent NVARCHAR(255)


   OPEN fkcursor
   FETCH NEXT FROM fkcursor INTO @name, @parent


   WHILE @@FETCH_STATUS = 0
   BEGIN
      EXECUTE('ALTER TABLE ' + @parent + ' DROP CONSTRAINT ' + @name)
      FETCH NEXT FROM fkcursor INTO @name, @parent
   END


   CLOSE fkcursor
   DEALLOCATE fkcursor


   -- Now drop the tables.
   DECLARE tbcursor CURSOR FOR
      SELECT name
      FROM dbo.sysobjects
      --WHERE OBJECTPROPERTY(id, N'IsUserTable') = 1 AND name LIKE 'Ae%'
      WHERE OBJECTPROPERTY(id, N'IsUserTable') = 1


   OPEN tbcursor
   FETCH NEXT FROM tbcursor INTO @name


   WHILE @@FETCH_STATUS = 0
   BEGIN
      EXECUTE('DROP TABLE ' + @name)
      FETCH NEXT FROM tbcursor INTO @name
   END


   CLOSE tbcursor
   DEALLOCATE tbcursor
END
GO


create table tb_user(
id int IDENTITY(1,1) primary key,
username varchar(20) not null,
password varchar(20) not null,
sex varchar(2) not null,
email varchar(50) not null,
oicq varchar(20) default null,
signature varchar(300) default null,
grade varchar(20) default null,
lxdz varchar(50),
tx varchar(30),
grzy varchar(50),
realname varchar(30)
);
insert into tb_user(username,password,sex,email,oicq,signature,grade,lxdz,tx,grzy,realname) values('TSoft','111','1','xiaoyu*****@sina.com','123','test','admin','test','2.gif','test','test');


create table tb_forum(
id int IDENTITY(1,1) primary key,
forumname varchar(20) not null,
manager varchar(100) default null,
createtime timestamp 
);
insert into tb_forum(forumname,manager)values('ASP','fish');
insert into tb_forum(forumname,manager)values('PHP','fish');
insert into tb_forum(forumname,manager)values('C#','fish');
insert into tb_forum(forumname,manager)values('.NET','fish');
insert into tb_forum(forumname,manager)values('VB','fish');
insert into tb_forum(forumname,manager)values('JSP','fish');


create table tb_topic(
id int IDENTITY(1,1) primary key,
content text,
author varchar(20) not null,
submittime timestamp ,
forumid int default 0,
title varchar(300) not null,
xq varchar(30) not null,
rq int default 0,
forumname varchar(20)
);

create table tb_response(
id int IDENTITY(1,1) primary key,
title varchar(300) not null,
content text,
author varchar(20) not null,
submittime timestamp ,
topicid int not null,
topicname varchar(100),
xq varchar(20) not null
);


mysql:


create database db_bbs;
use db_bbs;
#用户信息表
create table tb_user(
id int(11) auto_increment primary key not null,
username varchar(20) not null,
password varchar(20) not null,
sex varchar(2) not null,
email varchar(50) not null,
oicq varchar(20) default null,
signature varchar(300) default null,
grade varchar(20) default null,
lxdz varchar(50),
tx varchar(30),
grzy varchar(50),
realname varchar(30)
);
insert into tb_user(username,password,sex,email,oicq,signature,grade,lxdz,tx,grzy,realname) values('TSoft','111','1','xiaoyu*****@sina.com','123','test','admin','test','2.gif','test','test');
#论坛信息表
create table tb_forum(
id int(11) auto_increment primary key not null,
forumname varchar(20) not null,
manager varchar(100) default null,
createtime timestamp default current_timestamp
);
insert into tb_forum(forumname,manager)values('ASP','fish');
insert into tb_forum(forumname,manager)values('PHP','fish');
insert into tb_forum(forumname,manager)values('C#','fish');
insert into tb_forum(forumname,manager)values('.NET','fish');
insert into tb_forum(forumname,manager)values('VB','fish');
insert into tb_forum(forumname,manager)values('JSP','fish');
#主题信息表
create table tb_topic(
id int(4)  auto_increment primary key not null,
content text,
author varchar(20) not null,
submittime timestamp(8) default current_timestamp,
forumid int(4) default 0,
title varchar(300) not null,
xq varchar(30) not null,
rq int(4) default 0,
forumname varchar(20)
);
#insert into tb_topic(content,author,submittime,forumid,title)values('测试','快饿死的鱼','2007-08-20','1','测试');




#回复信息表
create table tb_response(
id int(11) not null auto_increment primary key,
title varchar(300) not null,
content text,
author varchar(20) not null,
submittime timestamp default current_timestamp,
topicid int(4) not null,
topicname varchar(100),
xq varchar(20) not null
);

























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值