2009年3月23日星期一

如何使用sql语句来创建数据表-----sql语句创建数据表

如何使用sql语句来创建sql2000或者sql2005数据库软件的数据表呢,这个对于初级编程爱好者人员来说是有难度的,要想成为真正的程序员必须要达到这一步,因为所有程序百分之九十九都会用到数据库,所以学会sql语句非常重要,首先我们要先学习一下如何用sql语句建表:

创建工作人员日志表结构
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tabworklogin]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tabworklogin]
GO

CREATE TABLE [dbo].[tabworklogin] (
[id] [int] IDENTITY (1, 1) NOT NULL primary key , 设置关键主键
[worktype] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[worktext] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[answers] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[worker] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[workdate] [datetime] not NULL default(getdate()), 默认系统时间
[xianshi] [int] NULL ,

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
这是一个创建数据表的语句,非常实用,
主要是用到了CREATE TABLE 语句,
如何添加默认值呢?
添加默认值
ALTER TABLE [dbo].[Taborders]
ADD DEFAULT 0 FOR [Issee]
GO
修改主健
ALTER TABLE [dbo].[Taborders]
ADD CONSTRAINT [Taborders_pk] PRIMARY KEY ([Id])
GO

修改字段类型
alter table tb alter column name nvarchar(200)
go

'修改默认时间
select * from tabcustomer
ALTER TABLE [dbo].[tabcustomer]
ADD DEFAULT gettime() FOR [regtime]
GO

没有评论:

wholesale retail company from china

achinaseller.com is a professional wholesale retail company, having our own factory with 5 years of wholesale retail experience. Achinaseller.com is also cooperating closely with many factories, so the price that we offer to the consumer is directly from the Chinese Factory. Without leaving your home, you could order your own products at achinaseller.com at the lowest price.
We service over 100,000 registered buyers, delivering to virtually every country in the world. Our warehouse and office are staffed by a young team of Chinese and Western staff.
Happy AchinaSeller buyers include frequent wholesale importers, famous ecommerce websites, eBay powersellers, retail shops and startup home import businesses. On a daily basis, we serve corporate buyers, drop-ship experts, home business Moms, and small bussiness wholesaler