您的位置:首页 > 博客中心 > 数据库 >

SQL语句创建表和数据库

时间:2022-03-14 03:59

创建数据库的SQL语句:

 1 use practice
 2 go 
 3 if exists (select * from sysobjects where name=‘practice‘)
 4 drop table Store_Information
 5 create table Store_Information
 6 (
 7   storeID int identity(1,1) primary key,--列属性"identity(起始值,递增量)"
 8   store_Name varchar not null,
 9   store_Money decimal null,
10   store_Date date not null,
11 )

 

删除数据库,SQL Server将数据库的清单存放在master系统数据库的sysdatabases表中,只需要查看该表是否存在于该数据库中就可以

了,语句如下:

1 use master -- 设置当前数据库为master,以便访问sysdatabases表
2 go 
3 if exists (select * from sysdatabases where name=‘practice‘)
4 drop database practice

创建表的SQL语句如下:

 

 1 use practice
 2 go 
 3 if exists (select * from sysobjects where name=‘practice‘)
 4 drop table Store_Information
 5 create table Store_Information
 6 (
 7   storeID int identity(1,1) primary key,--列属性"identity(起始值,递增量)"
 8   store_Name varchar not null,
 9   store_Money decimal null,
10   store_Date date not null,
11 )

 

热门排行

今日推荐

热门手游