SQL Server CREATE TABLE

Source: Internet
Author: User

based on the database that was created in the previous article, we continue to create data tables. T-the syntax for SQL database creation is as follows:CREATE  TABLETable name (field name 1 data type constraint, field name 1 data type constraint,...) The first is to create the Learner information table Stuinfo, here are some small details:IDENTITY(Start value, increment) is listed as the identity column, NUMERIC ( -,0) represents a 18-digit number, with a scale of 0.  UseStudb--set the current database to StudbGOIF EXISTS(SELECT *  fromsysobjectsWHEREName=' Stuinfo ')DROP  TABLEStuinfoCREATE  TABLEStuinfo/*-Create Student information sheet-*/(StunoCHAR(6) not  NULL,--School Number, non-empty (required)StunameVARCHAR( -) not  NULL,--name, non-empty (required)StuageINT   not  NULL,--age, int type defaults to 4 bytesStuid NUMERIC ( -,0),--ID NumberStuseatSMALLINT  IDENTITY(1,1),--seat number, auto numberStuaddressTEXT   --address, allow null, optional input)GOthen create the Student score table StumarksCREATE TABLEStumarks (ExamnoCHAR(7) not NULL,--Exam NumberStunoCHAR(6) not NULL,--School NumberWrittenexamINT   not NULL,--written resultsLabexamINT   not NULL    --Machine Test Results)GOWhen a stuinfo table exists in the table, how do I resolve the error again? We will certainly think of the same approach to database processing. Where do we go to test it? Oh, check the Name column in the system table sysobjects (object table) of the STUDB database. OK, now our database and the table are all created. We have specified the data type for each field when we are building the table, and have made basic restrictions and distinctions about the types of values that can be inserted. So what are the data types in SQL Server? Let's take a look at the next article. 

SQL Server CREATE TABLE

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.