MySQL creation table structure

tags: sql

  1. Create, edit, and delete data tables in Management Studio;
  2. Create, edit, and delete data tables using T-SQL;

Create and manage data table structures using T-SQL statements

T-SQL statement creation table structure

The table structure is as follows, based on the structure of the data table.
student:

Field Name Field type and length Description Note
sno char(9) Student number Main keyword
sname nvarchar(6) student name non empty
ssex nchar(1) Student gender Can be empty
sage int Student age Can be empty
sdept nvarchar(8) Student office department Can be empty

code show as below:

use student
create table student(
sno char(9) not null primary key,
sname nvarchar(6) not null,
ssex nchar(1),
sage int,
sdept nvarchar(8)
)

Course (Course Information Table):

Field Name Field type and length Description Note
cno char(4) Course No Main keyword
cname nvarchar(20) Course Title non empty
cpno char(4) First class Can be empty
ccredit int credit Can be empty

code show as below:

use student
create table course(
cno char(4) not null primary key,
cname nvarchar(20) not null,
cpno nchar(4),
ccredit int null,
)

SC (selection information table):

Field Name Field type and length Description Note
sno char(9) Student number Main keyword
cno char(4) Course No Main keyword
grade int Grade Can be empty

code show as below:

use student
create table sc(
sno char(9) not null,
cno char(4) not null,
grade int,
primary key ( sno, cno )
)

T-SQL statement modification table structure

(1) Add a new field "Class Name (Sclass)" character type to VARCHAR (10) in Table Student.

use student
alter table student 
add sclass vachar(1o)

(2) Remove field "Sclass" in Table Student;

use student
alter table student 
drop column sclass

(3) Modify the field length of the field name "sname" in the table Student is changed from the original 6 to 8;

use student
alter table student 
alter column snmae nvarchar(8)

Operation prompt

Create a table

(1) Steps in the management interface method:

Open the small plus number in front of the database name that has been created, right-click on the [Table] node, select the [New Table] command to open the watch designer window. Enter the column name in the table designer window. Select the data type and whether it is allowed to be empty, and click the right mouse button in front of the primary key field, select [Set Primary Key] option. It is also possible to identify the meaning of each field representation in the description of the column properties. After the design is complete, press the CTRL + S key button to save, enter the table name in the pop-up dialog box, click the [OK] button.

(2) Steps in the T-SQL statement method:

On the [SQL Server Management Studio] window, select the [New Query] button to start the SQL Editor window, enter the T-SQL statement at the cursor, click the [Execute] button.

2. Modify the table structure

(1) Steps in the management interface method:

On the table student you need to modify, right-click, select the [Designer] command, open [Table Designer], modify it in the need to modify, click the [Save] button after the modification is complete.

(2) Steps in the T-SQL statement method:

On the [SQL Server Management Studio] window, select the [New Query] button to start the SQL Editor window, enter the T-SQL statement at the cursor, click the [Execute] button.

Intelligent Recommendation

MySQL-02- creation table, constraint, modified structure, etc.

MySQL-02- creation table, constraint, modified structure, etc. Article catalog MySQL-02- creation table, constraint, modified structure, etc. Query database Design table: There are below the table Des...

Getting Started (5) Creation and Analysis of Table Structure of Mysql Database

Be careful to analyze the data before the form of the table, the field name is the abstract name of the data, the field attribute is the type and constraint of the data. When you build a table, you sh...

Mysql data table creation

When creating a data table, if you delete the data, you need to rearrange the primary key: 1, first delete the primary key in the original table: 2, re-add the primary key, set the following propertie...

MySQL table creation and modification

Create a table View table Rename table View table structure Change table structure Delete table  ...

MySQL table creation and deletion

In the MySQL database, the database is the first level, and then the data table, then the data row, today we talk about the creation and deletion MySQL database table. In the creation of the table str...

More Recommendation

MySQL-table creation

Everyone must have a question. What is the table? You can understand it as a relationship (discrete mathematics X-Y), each row and column has a corresponding correspondence, just like a mathematical c...

mysql table creation

  four,table 1, the creation of the table 2. Table replication  Definition: Create query results as a table Method structure:CREATE TABLE Table Name as selectQuery quibble 1) Complete copyem...

MySQL table creation constraints

————Primary key constraint create table user( id int primary key, name varchar(20) );//Set id as the primary key constraint ——Add the first data, id=1; mysql> in...

MySQL table creation and maintenance

1. Import test data [root@server ~]# wget https://launchpadlibrarian.net/24493586/employees_db-full-1.0.6.tar.bz2   mysql> source /root/employees_db/employees.sql ;   View: mysql> use ...

mysql _ database table creation

---1. Create an empty list First, when using a database for the first time, you need to create a database before you can create a table. Taking the student system as an example, the database statement...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top