Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - sql statement creates table
sql statement creates table

The program function to create a new table is:

create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

Specifically:

Determine whether the database exists before creating it

if exists (select * from sysdatabases where name='databaseName')

drop database databaseName

go

Create DATABASE databasename

on primary--it belongs to the primary file group by default and can be omitted

(

p>

/*--Detailed description of the data file--*/

name='databasename_data',--The logical name of the main data file

filename='' Storage location: \databasename_data.mdf', --The physical name of the main data file

size=numeric value mb, --The initial size of the main data file

maxsize=numeric value mb, - - The maximum growth value of the master data file

filegrowth=Number%--the growth rate of the master data file

)

log on

(

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

name='databasename_log', -- The logical name of the log file

filename='storage directory:\databasename_log.ldf', -- the physical name of the log file

size=numeric value mb, --the initial size of the log file

filegrowth =Number%--The growth value of the log file

)

Structured Query Language (Structured Query Language) is referred to as SQL. Structured Query Language is a database query and programming language. , used to access data and query, update and manage relational database systems;

SQL statements are a language for operating databases.

Extended information

1. Common statements

Update: update table1 set field1=value1 where range

Search: select * from table1 where field1 like '%value1%' (all strings containing the pattern 'value1')

Sort: select * from table1 order by field1,field2 [desc]

Sum :select sum(field1) as sumvalue from table1

Average: select avg(field1) as avgvalue from table1

Maximum: select max(field1) as maxvalue from table1

Minimum: select min(field1) as minvalue from table1[separator]

2. Advanced query

A: UNION operator

UNION operator A result table is derived by combining two other result tables (for example, TABLE1 and TABLE2) and eliminating any duplicate rows in the tables. When ALL is used with UNION (that is, UNION ALL), duplicate rows are not eliminated. In both cases, every row in the derived table comes from either TABLE1 or TABLE2.

B: EXCEPT operator

The EXCEPT operator derives a result table by including all rows in TABLE1 but not in TABLE2 and eliminating all duplicate rows. When ALL is used with EXCEPT (EXCEPT ALL), duplicate rows are not eliminated.

C: INTERSECT operator

The INTERSECT operator derives a result table by including only rows that are present in both TABLE1 and TABLE2 and eliminating any duplicate rows. When ALL is used with INTERSECT (INTERSECT ALL), duplicate rows are not eliminated.

Note: Several query result rows using operator words must be consistent.

Baidu Encyclopedia-SQL statement list