赞
踩
use master
if exists(select * from sysdatabases where name =’CTDDBS’)
drop database CTDDBS
go
–create data
CREATE DATABASE CTDDBS
ON PRIMARY(
NAME=’data_1’,
filename=’d:\data_1.mdf’,
size=3,
maxsize=50.
filegrowth=1)
log on
(
name=’data_log’,
filename=’d:\data_log.ldf’,
size=1,
filegrowth=10%
)
go
–create table
use CTDDBS
go
CREATE TABLE LoginInfo
(
LoginID int IDENTITY(1,1) NOT NULL ,
Admin char(10) NOT NULL,
Pwd char(10) NOT NULL
)
– drop table
DROP TABLE LoginInfo
–CREATE CONSTRAINT
ALTER TABLE LoginInfo
ADD CONSTRAINT PK_LoginID PRIMARY KEY (LoginID) –add primary key
ALTER TABLE LoginInfo
ADD CONSTRAINT UQ_Admin UNIQUE (Admin) –add unique key
ALTER TABLE LoginInfo
ADD CONSTRAINT DF_Pwd DEFAULT (‘123456’) FOR Pwd –add defualt constraint
ALTER TABLE LoginInfo
ADD CONSTRAINT CK_Pwd CHECK (Pwd>7 and Pwd<25) –add check constraint
ALTER TABLE LoginInfo
ADD CONSTRAINT FK_LoginID
FOREIGN KEY (LoginID) REFERENCES StuInfo(StuID) –add references constraint
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。