创建表的sql语句
本文章提供了三款创建表的sql语句实例代码,一一举例测试并说明了如何利用sql创建数据表与数据库说明实例。
本文章提供了三款创建表的sql语句实例代码,一一举例测试并说明了如何利用sql创建数据表与说明实例。
use [master]
go
if exists(select 1 from sysdatabases where name=n'hktemp')
begin
drop database hktemp --如果数据库存在先删掉数据库
end
go
create database hktemp
on
primary --创建主数据库文件
(
name='hktemp',
filename='e:databaseshktemp.dbf',
size=5mb,
maxsize=20mb,
filegrowth=1mb
)
log on --创建日志文件
(
name='hktemplog',
filename='e:databaseshktemp.ldf',
size=2mb,
maxsize=20mb,
filegrowth=1mb
)
go
--添加表
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
--添加注释
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'邮箱' , @level0type=n'schema',@level0name=n'dbo', @level1type=n'table',@level1name=n'hksj_user', @level2type=n'column',@level2name=n'semail'
实例二
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),
msclongitude 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),
longitude 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,
longitude 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,
longitude 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),
longitude decimal (8,6),
rxlev decimal (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, msclongitude, 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, longitude, 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, longitude, 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, longitude, latitude, direction, radious, 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, longitude, rxlev);
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);
方法三
举例:
create table [学生]
(
学号 char(8) not null primarykey,
姓名 varchar(8) not null
)
上面写了两列,其余差不多,至于不允许有重复姓名,加上“约束”就行了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

"Usage of Division Operation in OracleSQL" In OracleSQL, division operation is one of the common mathematical operations. During data query and processing, division operations can help us calculate the ratio between fields or derive the logical relationship between specific values. This article will introduce the usage of division operation in OracleSQL and provide specific code examples. 1. Two ways of division operations in OracleSQL In OracleSQL, division operations can be performed in two different ways.

Oracle and DB2 are two commonly used relational database management systems, each of which has its own unique SQL syntax and characteristics. This article will compare and differ between the SQL syntax of Oracle and DB2, and provide specific code examples. Database connection In Oracle, use the following statement to connect to the database: CONNECTusername/password@database. In DB2, the statement to connect to the database is as follows: CONNECTTOdataba

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

This article will interest you if you are interested in using GIMP for pixel art creation on Windows. GIMP is a well-known graphics editing software that is not only free and open source, but also helps users create beautiful images and designs easily. In addition to being suitable for beginners and professional designers alike, GIMP can also be used to create pixel art, a form of digital art that utilizes pixels as the only building blocks for drawing and creating. How to Create Pixel Art in GIMP Here are the main steps to create pixel pictures using GIMP on a Windows PC: Download and install GIMP, then launch the application. Create a new image. Resize width and height. Select the pencil tool. Set the brush type to pixels. set up

What is Identity in SQL? Specific code examples are needed. In SQL, Identity is a special data type used to generate auto-incrementing numbers. It is often used to uniquely identify each row of data in a table. The Identity column is often used in conjunction with the primary key column to ensure that each record has a unique identifier. This article will detail how to use Identity and some practical code examples. The basic way to use Identity is to use Identit when creating a table.

Many friends expressed that they want to know how to create a family in Gree+ software. Here is the operation method for you. Friends who want to know more, come and take a look with me. First, open the Gree+ software on your mobile phone and log in. Then, in the options bar at the bottom of the page, click the "My" option on the far right to enter the personal account page. 2. After coming to my page, there is a "Create Family" option under "Family". After finding it, click on it to enter. 3. Next jump to the page to create a family, enter the family name to be set in the input box according to the prompts, and click the "Save" button in the upper right corner after entering it. 4. Finally, a "save successfully" prompt will pop up at the bottom of the page, indicating that the family has been successfully created.
