SQL Server Getting Started with mastering----table operations

Source: Internet
Author: User

1  UseQzone2 3 --select * from sysobjects where name= ' Q_user '4 if object_id('Q_user','u') is  not NULL   --obejct_id a method based on table sysobjects (object name, object type)5 Drop TableQ_user--Delete a table6 Create TableQ_user7 (8Uidint,--identity (10001,1),--PRIMARY KEY constraint9Ulognamenvarchar( -)Unique,--Unique constraint ck__q_user__upwd__1cf15040 (automatically generated constraint name is inconvenient for subsequent operations)TenUNamenvarchar( -), OneUpwdnvarchar( -)Check(Len(UPWD)<= -),--CHECK Constraints AUisonlinebit default(0),--Default Constraints -Uisfrezeebit, -Ufrezeetimenvarchar( -), theUismulloginbit  -     --PRIMARY Key -     constraintPk_uidPrimary Key(uId)--You can specify a primary key name -     --primary KEY (UId) +     --primary KEY (ULOGNAME,UPWD) two together to form a primary key -     --FOREIGN Key +     --Foreign Key (Sno) references student (Sno) A     --all constraints are similar to primary keys at ) - execsp_rename'Q_user','q_users' --(Modify table name) - execsp_rename'q_users','Q_user' - --can also be used to modify the specified - execsp_rename'Q_user.uismullogin','Upwds' - execsp_rename'Q_user.upwds','Uismullogin'--There's a constraint that doesn't seem to be renamed in  -  to Alter Table Book + AddBook_copy_novarchar(Ten), Publish_datesmalldatetime  -  the Alter TableQ_user * --add test nvarchar check (len (test) >6), SS Int--Add a column $ --Drop Column Test-when you delete a constrained column, you delete its subordinate columns (if this is done directly with visual action)Panax Notoginseng --ALTER column Uisonline INT--Modify the type to remove its subordinate columns first (if this is done directly with visual action) - --add constraint Df_uisonline default (0) for Uisonline the --add constraint ck_uisonline check (uisonline in (0,1)) + --add constraint Pk_stuno primary key (Stuno) A --add constraint uq_stuid unique (stuid) the --ALTER column uisonline int NOT null + DropCk_uisonline--Delete Constraint

SQL Server Getting Started with mastering----table operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.