SQL statement used to create a table

Source: Internet
Author: User
Tags how to use sql
This article provides three SQL statement instance codes for table creation, one-to-one test, and explains how to use SQL to create data tables and databases.

This article provides three SQL statement instance codes for table creation, one-to-one test, and explains how to use SQL to create data tables and databases.

This article provides three SQL statement instance codes for table creation, one-to-one test and explains how to use SQL to create data tables and explain instances.

Use [master]
Go
If exists (select 1 from sysdatabases where name = n' hktemp ')
Begin
Drop database hktemp -- if the database exists, delete the database first.
End
Go
Create database hktemp
On
Primary -- create a master database file
(
Name = 'hktemp ',
Filename = 'e: databaseshktemp. dbf ',
Size = 5 mb,
Maxsize = 20 mb,
Filegrowth = 1 mb
)
Log on -- create a log file
(
Name = 'hktemplog ',
Filename = 'e: databaseshktemp. ldf ',
Size = 2 mb,
Maxsize = 20 mb,
Filegrowth = 1 mb
)
Go
-- Add a table
If not exists (select * from sys. objects where object_id = object_id (n'hksj _ user') and type in (n'u '))
Begin
Create table hksj_user
(
Id int identity (1, 1) not null,
Sname nvarchar (20) not null,
Snickname nvarchar (20 ),
Spassword nvarchar (30) not null,
Dcreatedate datetime,
Screator nvarchar (20 ),
Semail nvarchar (50 ),
Sphone nvarchar (50 ),
Sidentifyid nvarchar (30 ),
Dlasttimelogon datetime
Primary key clustered
(
Id asc
) With (ignore_dup_key = off) on [primary]
) On [primary]
End
Go
-- Add comments
Exec sys. sp_addextendedproperty @ name = n' ms _ description', @ value = n' ', @ level0type = n' schema', @ level0name = n' dbo ', @ level1type = n' table ', @ level1name = n' hksj _ user', @ level2type = n' column', @ level2name = n' sname'
Go
Exec sys. sp_addextendedproperty @ name = n' ms _ description', @ value = n' mailbox ', @ level0type = n' schema', @ level0name = n' dbo ', @ level1type = n' table ', @ level1name = n' hksj _ user', @ level2type = n' column', @ level2name = n' semail'


Instance 2

Drop table cell_tch;
Drop table MS;
Drop table msc;
Drop table bsc;
Drop table bts;
Drop table cell;
Drop table antenna;
Drop table data;
Drop table test;
Drop table neighbor;

Create table msc (
Mscid integer not null,
Mscname character (10 ),
Msccompany character (10 ),
Msclong1_decimal (9, 6 ),
Msclatitude decimal (8, 6 ),
Mscaltitude integer,
Primary key (mscid ));

Create table bsc (
Bscid integer not null,
Bscname character (10 ),
Bsccompany character (10 ),
Longbench decimal (9, 6 ),
Latitude decimal (8, 6 ),
Mscid integer,
Primary key (bscid ),
Foreign key (mscid) references msc (mscid ));

Create table bts (
Btsname character (20) not null,
Bscid integer not null,
Longbench decimal (9, 6 ),
Latitude decimal (8, 6 ),
Altitude integer,
Btscompany character (10 ),
Btspower decimal (2, 1 ),
Primary key (btsname ),
Foreign key (bscid) references bsc (bscid ));

Create table cell (
Cellid integer not null,
Btsname character (20 ),
Areaname character (10 ),
Lac integer,
Longbench decimal (9, 6 ),
Latitude decimal (8, 6 ),
Direction integer,
Radious integer,
Antnum integer,
Bcch integer,
Primary key (cellid ),
Foreign key (btsname) references bts (btsname ));

Create table MS (
Imei bigint not null,
Msisdn bigint,
Username varchar (10 ),
Mscompany varchar (20 ),
Gsmmsense integer,
Gsmmsheight decimal (3, 2 ),
Gsmmspfout decimal (3, 2 ),
Mzone character (10 ),
Cellid integer,
Primary key (imei ),
Foreign key (cellid) references cell (cellid ));

Create table antenna (
Cellid integer not null,
Antennahigh integer,
Halfpangle integer,
Maxattenuation integer,
Gain integer,
Anttilt integer,
Pt integer,
Mspwr integer,
Primary key (cellid ));

Create table cell_tch (
Cellid integer,
Freq integer,
Foreign key (cellid) references cell (cellid ));

Create table data (
Date integer not null,
Time integer not null,
Cellid integer not null,
Ntch integer,
Traff decimal (9, 7 ),
Rate decimal (10, 9 ),
Thtraff decimal (9, 7 ),
Callnum integer,
Congsnum integer,
Callcongs decimal (10, 9 ),
Primary key (date, time, cellid ));

Create table test (
Keynum integer not null,
Cellid integer,
Latitude decimal (9, 6 ),
Longbench decimal (8, 6 ),
Rxlevdecimal (9, 6 ),
Primary key (keynum ),
Foreign key (cellid) references cell (cellid ));

Create table neighbor (
Cellid integer,
Adjcellid integer,
Celllac integer,
Adjcelllac integer,
Foreign key (cellid) references cell (cellid ));
Import from "c: msc.csv" of del method p (1, 2, 3, 4, 5, 6) messages "1" insert into db2admin. msc (mscid, mscname, msccompany, msclongpolling, msclatitude, mscaltitude );

Import from "c: bsc.csv" of del method p (1, 2, 3, 4, 5, 6) messages "1" insert into db2admin. bsc (bscid, bscname, bsccompany, longpolling, latitude, mscid );

Import from "c: bts.csv" of del method p (1, 2, 3, 4, 5, 6, 7) messages "1" insert into db2admin. bts (btsname, bscid, longpolling, latitude, altitude, btscompany, btspower );

Import from "c: cell.csv" of del method p (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) messages "1" insert into db2admin. cell (cellid, btsname, areaname, lac, longpolling, latitude, direction, radous, antnum, bcch );

Import from "c: data.csv" of del method p (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) messages "1" insert into "data" (date, time, cellid, ntch, traff, rate, thtraff, callnum, congsnum, callcongs );

Import from "c: ms.csv" of del method p (1, 2, 3, 4, 5, 6, 7, 8, 9) messages "1" insert into db2admin. ms (imei, msisdn, username, mscompany, gsmmspsense, gsmmsheight, gsmmspfout, mzone, cellid );

Import from "c: cell_tch.csv" of del method p (1, 2) messages "1" insert into db2admin. cell_tch (cellid, freq );

Import from "c: test.csv" of del method p (1, 2, 3, 4, 5) messages "1" insert into db2admin. test (keynum, cellid, latitude, longpolling, rxev );

Import from "c: antenna.csv" of del method p (1, 2, 3, 4, 5, 6, 7, 8) messages "1" insert into db2admin. antenna (cellid, antennahigh, halfpangle, maxattenuation, gain, anttilt, pt, mspwr );

Import from "c: neighbor.csv" of del method p (1, 2, 3, 4) messages "1" insert into db2admin. neighbor (cellid, adjcellid, celllac, adjcelllac );


Method 3

Example:
Create table [Student]
(
Student ID char (8) not null primarykey,
Name varchar (8) not null
)

The above two columns are written, and the rest are similar. duplicate names are not allowed, just add "constraints.

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.