1.一直都记不太清楚,需要新建一个数据库和表的脚本是怎样的,恰巧今天翻到了,特地记录下来,希望以后用的时候记住吧! create database testdb00; use testdb00; create table userinfo( id int not null auto_increment, name varchar(20) not null, age int not null, sex tinyint(1) not null, primary key (id) ) 2.建好的效果:…
--判断数据库是否存在 IF EXISTS (SELECT * FROM MASTER.sys.sysdatabases WHERE NAME = '库名') PRINT 'exists ' else PRINT 'not exists' -- 判断要创建的表名是否存在 IF EXISTS (Select * From sysObjects Where Name ='表名' And Type In ('S','U')) PRINT 'exists' ELSE PRINT 'not exists'…
--IF DB_ID('testdb') IS NULL --CREATE DATABASE testdb USE master GO IF EXISTS ( SELECT * FROM sys.databases WHERE name = 'TestDB' ) --是否存在,存在删除 DROP DATABASE TestDB --GO -- EXEC xp_cmdshell 'mkdir D:\SQL' --调用DOS命令创建文件夹 CREATE DATABASE TestDB ON PRIM…