Joke Collection Website - Bulletin headlines - How does sql sever create a table?

How does sql sever create a table?

There are two ways to create databases and tables:

First, visual operation.

1. Create a database

Right-click the selected database, select New Database in the dialog box that appears, and then fill in the name of the database in the New dialog box.

Create data table

Right-click a table under the database, and a new table option will appear at the top of the dialog box. The new dialog box has three columns: column name, data type and allowed null values. Here, you can add columns of the table and save Ctrl+S after adding the columns, or click Save above, fill in the name of the table and confirm the creation.

Second, using SQL statements to create

-1. Create a database

Create? Database? stuDB? -stuDB is the name of the database.

Open? Elementary? - ? By default, it belongs to the primary filegroup and can be omitted.

(

/*-Specific description of data file-*/

name='stuDB_data ',? - ? Logical name of the master data file

filename='D:\stuDB_data.mdf ',? - ? The physical path and name of the master data file.

size=5mb,? -Initial size of the main data file

maxsize= 100mb,? - ? Maximum growth of master data file

File growth = 15%- growth rate of main data file.

)

Journal? exist

(

/*-The specific description of the log file, and the meaning of each parameter is the same as above-*/

name='stuDB_log ',

filename='D:\stuDB_log.ldf ',

Size =2mb,

File growth = 1mb

)

-2. Create a data table

Use? StuDB-Use a database (create a table under the database)

Going?

What if? Exist (select? *? From where? sysobjects? Where is it? Name =' stu marks ')- Query whether the table already exists in the database.

Descending? Table? StuMarks-If the table exists, delete it; If it does not exist, don't execute this sentence.

Create? Table? stuMarks? Stumarks is the name of the table.

(

ExamNo? int? Identity (1, 1)? Elementary? Key-Column Name Data Type Constraint

Stuno? char(6)? Isn't it? Null,-Does the column name data type allow the insertion of null values?

writtenExam? int? Isn't it? Empty,

LabExam? int? Isn't it? empty

)

go to

- ? Among them, the column attribute "identity"? Indicates that the "ExamNo" column is automatically numbered. Also known as identity column alter. Table? Table name

Supplement? Constraints? Constraint name? Constraint type? Specific constraint description

Alter? Table? Table name

Descending? Constraints? Constraint name