+
表名,你这里就可以是这样的:desc
members。如果是要看有哪些表,可以执行命令:
show
tables,
查看有哪些数据库则:show
databases
看看有什么不对的地方可以自己再修改一下,不会的话再追问吧,我给你改IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'xin')
DROP DATABASE [xin]
GO
CREATE DATABASE [xin] ON (NAME = N'xin_Data', FILENAME = N'D:\Program Files\Microsoft SQL Server\MSSQL\data\xin_Data.MDF' , SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N'xin_Log', FILENAME = N'D:\Program Files\Microsoft SQL Server\MSSQL\data\xin_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
GO
use [xin]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_orders_members]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[orders] DROP CONSTRAINT FK_orders_members
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_orders_products]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[orders] DROP CONSTRAINT FK_orders_products
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[orders]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[orders]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[members]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[members]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[products]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[products]
GO
CREATE TABLE [dbo].[members] (
[m_id] [varchar] (4) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[m_account] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[m_name] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[m_sex] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
[m_birth] [datetime] NULL ,
[m_address] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[m_salary] [money] NULL ,
[m_password] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[products] (
[p_no] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[p_name] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[p_date] [datetime] NULL ,
[p_quantity] [int] NULL ,
[p_price] [money] NULL ,
[p_information] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[orders] (
[p_no] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[m_id] [varchar] (4) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[m_account] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[o_no] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[o_quantity] [int] NULL ,
[o_date] [datetime] NULL ,
[o_confirm_state] [char] (1) COLLATE Chinese_PRC_CI_AS NULL ,
[o_pay_state] [char] (1) COLLATE Chinese_PRC_CI_AS NULL ,
[o_send_state] [char] (1) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[members] WITH NOCHECK ADD
PRIMARY KEY CLUSTERED
(
[m_id]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[products] WITH NOCHECK ADD
PRIMARY KEY CLUSTERED
(
[p_no]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[members] WITH NOCHECK ADD
CONSTRAINT [DF__members__m_birth__77BFCB91] DEFAULT (getdate()) FOR [m_birth]
GO
ALTER TABLE [dbo].[products] WITH NOCHECK ADD
CONSTRAINT [DF__products__p_date__7A9C383C] DEFAULT (getdate()) FOR [p_date],
CHECK ([p_quantity] <1000)
GO
ALTER TABLE [dbo].[orders] WITH NOCHECK ADD
CONSTRAINT [DF__orders__o_date__7E6CC920] DEFAULT (getdate()) FOR [o_date],
CHECK ([o_quantity] >0)
GO
ALTER TABLE [dbo].[orders] ADD
CONSTRAINT [FK_orders_members] FOREIGN KEY
(
[m_id]
) REFERENCES [dbo].[members] (
[m_id]
),
CONSTRAINT [FK_orders_products] FOREIGN KEY
(
[p_no]
) REFERENCES [dbo].[products] (
[p_no]
)
GO
连接数据库的用户的默认架构是sa,所以会在sa架构下寻找members表,如果sa架构下没有members表或者没有表的访问权限就会提示对象无效了。楼主检查下members表的架构名是什么,在members表前加上架构名
比如members表如果是dbo架构下的,就改成dbo.members
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)