1

我正在尝试在 SQL Server 2012 Management Studio 中创建一个表。

我想创建一个包含列的表:categorycustomerCostumePaymentrental

这是我到目前为止的SQL:

CREATE TABLE dbo.CATEGORY
(
    CATEGORY_ID     CHAR(5)     PRIMARY KEY,
    CATEGORY_DESC   CHAR(50)    NOT NULL
);

CREATE TABLE dbo.COSTUME
(
    Costume_ID              CHAR(5), 
    Costume_Desc            CHAR(50), 
    Costume_Size            CHAR(5),
    Costume_RentalPricE     DECIMAL(12,2),
    Category_ID             CHAR(5)
);

CREATE TABLE dbo.CUSTOMER
(
    Customer_ID         CHAR(5),
    Customer_LastName   CHAR(50),
    Customer_FirstName  CHAR(50),
    Customer_Address    CHAR(30),
    Customer_City       CHAR(50),
    Customer_State      CHAR(2),
    Customer_Zip        CHAR(10),
    Customer_Phone      CHAR(10),
    Category_ID         CHAR(5)
);

CREATE TABLE dbo.Payment
(
    Payment_ID          CHAR(5),
    Customer_ID         CHAR(5),
    Payment_Date        DATE,
    Payment_Amount      DECIMAL(12,2),
    Payment_Comment     VARCHAR,
);

CREATE TABLE dbo.Rental
(
    Rental_ID       --it says this needs to be Long integer for field size?
    Customer_ID         CHAR(5),
    Costume_ID          CHAR(5),
    Rental_Date         DATE,   
    Rental_DueDate      DATE,
    Rental_CheckIn      --YES OR NO? i'M NOT SURE HOW TO DO THIS. 
    Rental_Penalty      DECIMAL(12,2)
);

如何创建布尔列和长字段?

4

2 回答 2

5
USE COSTUMERENTAL;

CREATE TABLE dbo.CATEGORY  -- should always specify schema
(
    CATEGORY_ID       CHAR(5)    PRIMARY KEY, -- can't be two data types
    CATEGORY_DESC     CHAR(50)   NOT NULL
); -- don't need to specify PRIMARY KEY twice

--USE COSTUMER RENTAL; -- is there a space in the name or not?

CREATE TABLE dbo.COSTUME
(
    Costume_ID              CHAR(5), -- need commas
    Costume_Desc            CHAR(50), 
    Costume_Size            CHAR(5),
    Costume_RentalPricE     DECIMAL(12,2), -- Number isn't a valid SQL Server data type  
    Category_ID             CHAR(5)
); -- need closing brackets; also should always use semi-colons to terminate
于 2013-04-14T20:28:54.783 回答
1

为 Server Management Studio 创建表语法:

Microsoft's SQL Server数据库中,创建如下表:

CREATE TABLE dbo.MYTABLE
(
    my_integer       INTEGER PRIMARY KEY, //int −2,147,483,648 to 2,147,483,647
    my_varchar       VARCHAR(100),        //strings of characters
    my_forcedwidth   CHAR(50),            //fixed width of 50 chars
    my_yes_no        BIT,                 //holds 0 or 1
    my_decimal       DECIMAL(12,2)        //precision number.
    my_bigint        Bigint               //big integer
);

有关数据类型的完整列表:http: //www.connectionstrings.com/sql-server-data-types-reference/

于 2013-10-13T19:11:54.170 回答