SQL Server Base Language

Source: Internet
Author: User

This blog is about the database, data tables, fields, constraints and other simple additions and deletions of the operation (in addition to the recorded operation).

I. Database level

Increase:

1 CREATE DATABASE <Data table name>2  on  PRIMARY  --the default belongs to the primary primary filegroup, which omits3 (  4NAME='Studb_data',--logical name of the master data file5FILENAME='D:\project\stuDB_data.mdf',--physical name of the master data file6SIZE=5MB,--Primary Data file Initial size7MAXSIZE=100MB,--maximum number of main data file growth8FileGrowth= the%   --growth rate of master data files9 )Ten LOG  on One (   ANAME='Studb_log', -FILENAME='D:\project\stuDB_log.ldf', -SIZE=2MB, theFileGrowth=1MB -)

By deleting:

DROP DATABASE < database name >;

Check:

SELECT *  from sysdatabases;

Change:

1 ALTER DATABASE <Original database name>MODIFY NAME= <New database name>; 2 / EXECSp_renamedb'< original database name >','< New database name >';3 4 5 ALTER DATABASE <Database name>MODIFYFILE(NAME= <Original logical file name>, NEWNAME= <New Logical file name>);

Second, the data table level:

Increase:

1 CREATE TABLE <Table name>2 (3        <Column Name> <Data type>[< column-level integrity constraints >]4 ... ..5         [< table-level integrity constraints >]   6          ...7);

By deleting:

DROP TABLE < table name > ;

Check:

SELECT *  from SYS. TABLES;

Change:

EXEC ' < original data table name > ' ' < New data table name > ';

Third, field level

Increase:

ALTER TABLE < table name >ADD< new column name >< data type >[   ] ;

By deleting:

ALTER TABLE < table name >DROP< column name >;

Check:

SELECT  from WHERE id=object_id('< table name >'); View field data type information SQL statements are more complex , no write, graphical interface available

Change:

ALTER TABLE < table name >ALTERcolumn< column name >< data type  >; EXEC ' < table name. Original Column name > ' ' < new column name > ';

Iv. constraint level

Increase:

ALTER TABLE < table name >ADD< table-level integrity constraints >  - table-level integrity constraints, Take the PRIMARY KEY constraint as an example: CONSTRAINT < pick constraint name > FOREIGN key (< field name >);

By deleting:

ALTER TABLE < table name >DROPCONSTRAINT< integrity constraint name >;

Check:

-- View constraints specific information more complex, not write, the use of graphical interface

Change:

-- perform the delete and execute the increment first

V. Index level

Increase:

CREATE [UNIQUE | CLUSTERED]index< index name >on< table name >( < column name >[ASC | DESC], ... );

By deleting:

DROP INDEX < index name >;

Check:

-- Graphical Interface

Change:

ALTER INDEX < old index name >to< new index name >;

SQL Server Base Language

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.