网络编程
位置:首页>> 网络编程>> 数据库>> 如何用SQL语句来建表?

如何用SQL语句来建表?

  发布时间:2010-06-13 14:38:00 

标签:sql,表,数据库

如何用SQL 建表?


    如下:

CREATE TABLE statement                                                          
                                                                                  
  CREATE TABLE [<database>.[<owner>].]<table_name>                              
                                                                            
      {<col_name> <column_properties> [<constraint> [<constraint>                
            [... <constraint>]]]                                                  
      | [[,] <constraint>]}                                                      
            [[,] {<next_col_name> |                                                
            <next_constraint>}...]                                                
                                                                                  
  [ON <segment_name>]                                                              
                                                                                  
  <column_properties> =                                                            
      <datatype> [NULL | NOT NULL | IDENTITY[(<seed>, <increment>)]]              
  <constraint> =                                                                  
    For a PRIMARY KEY constraint:                                                  
      [CONSTRAINT <constraint_name>]                                              
            PRIMARY KEY [CLUSTERED | NONCLUSTERED]                                
                (<col_name> [, <col_name2> [..., <col_name16>]])                  
                [ON <segment_name>]                                              
    For a UNIQUE constraint:                                                      
      [CONSTRAINT <constraint_name>]                                              
            UNIQUE [CLUSTERED | NONCLUSTERED]                                      
                (<col_name> [, <col_name2> [..., <col_name16>]])                  
                [ON <segment_name>]                                              
    For a FOREIGN KEY constraint:                                                  
      [CONSTRAINT <constraint_name>]                                              
            [FOREIGN KEY (<col_name> [, <col_name2>                                
                [..., <col_name16> ]])]                                          
                REFERENCES [<owner>.]<ref_table> [(<ref_col>                      
                [, <ref_col2> [..., <ref_col16>]])]                              
    For a DEFAULT constraint:                                                      
      [CONSTRAINT <constraint_name>]                                              
            DEFAULT {<constant_expression> | <niladic-function> | NULL}            
                [FOR <col_name>]                                                  
    For a CHECK constraint(s):                                                    
      [CONSTRAINT <constraint_name>]                                              
            CHECK [NOT FOR REPLICATION] (<expression>)                           

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com